Commit 3219b3b7 authored by Nadia Derbey's avatar Nadia Derbey Committed by Linus Torvalds

idr: make idr_get_new* rcu-safe

Make the idr_get_new* routines rcu-safe.
Signed-off-by: default avatarNadia Derbey <Nadia.Derbey@bull.net>
Reviewed-by: default avatar"Paul E. McKenney" <paulmck@us.ibm.com>
Cc: Manfred Spraul <manfred@colorfullife.com>
Cc: Jim Houston <jim.houston@comcast.net>
Cc: Pierre Peiffer <peifferp@gmail.com>
Acked-by: default avatarRik van Riel <riel@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 944ca05c
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
* Modified by George Anzinger to reuse immediately and to use * Modified by George Anzinger to reuse immediately and to use
* find bit instructions. Also removed _irq on spinlocks. * find bit instructions. Also removed _irq on spinlocks.
* *
* Modified by Nadia Derbey to make it RCU safe.
*
* Small id to pointer translation service. * Small id to pointer translation service.
* *
* It uses a radix tree like structure as a sparse array indexed * It uses a radix tree like structure as a sparse array indexed
...@@ -96,7 +98,7 @@ static void idr_mark_full(struct idr_layer **pa, int id) ...@@ -96,7 +98,7 @@ static void idr_mark_full(struct idr_layer **pa, int id)
* @gfp_mask: memory allocation flags * @gfp_mask: memory allocation flags
* *
* This function should be called prior to locking and calling the * This function should be called prior to locking and calling the
* following function. It preallocates enough memory to satisfy * idr_get_new* functions. It preallocates enough memory to satisfy
* the worst possible allocation. * the worst possible allocation.
* *
* If the system is REALLY out of memory this function returns 0, * If the system is REALLY out of memory this function returns 0,
...@@ -170,7 +172,7 @@ static int sub_alloc(struct idr *idp, int *starting_id, struct idr_layer **pa) ...@@ -170,7 +172,7 @@ static int sub_alloc(struct idr *idp, int *starting_id, struct idr_layer **pa)
new = get_from_free_list(idp); new = get_from_free_list(idp);
if (!new) if (!new)
return -1; return -1;
p->ary[m] = new; rcu_assign_pointer(p->ary[m], new);
p->count++; p->count++;
} }
pa[l--] = p; pa[l--] = p;
...@@ -226,7 +228,7 @@ build_up: ...@@ -226,7 +228,7 @@ build_up:
__set_bit(0, &new->bitmap); __set_bit(0, &new->bitmap);
p = new; p = new;
} }
idp->top = p; rcu_assign_pointer(idp->top, p);
idp->layers = layers; idp->layers = layers;
v = sub_alloc(idp, &id, pa); v = sub_alloc(idp, &id, pa);
if (v == IDR_NEED_TO_GROW) if (v == IDR_NEED_TO_GROW)
...@@ -245,7 +247,8 @@ static int idr_get_new_above_int(struct idr *idp, void *ptr, int starting_id) ...@@ -245,7 +247,8 @@ static int idr_get_new_above_int(struct idr *idp, void *ptr, int starting_id)
* Successfully found an empty slot. Install the user * Successfully found an empty slot. Install the user
* pointer and mark the slot full. * pointer and mark the slot full.
*/ */
pa[0]->ary[id & IDR_MASK] = (struct idr_layer *)ptr; rcu_assign_pointer(pa[0]->ary[id & IDR_MASK],
(struct idr_layer *)ptr);
pa[0]->count++; pa[0]->count++;
idr_mark_full(pa, id); idr_mark_full(pa, id);
} }
...@@ -710,7 +713,8 @@ int ida_get_new_above(struct ida *ida, int starting_id, int *p_id) ...@@ -710,7 +713,8 @@ int ida_get_new_above(struct ida *ida, int starting_id, int *p_id)
return -EAGAIN; return -EAGAIN;
memset(bitmap, 0, sizeof(struct ida_bitmap)); memset(bitmap, 0, sizeof(struct ida_bitmap));
pa[0]->ary[idr_id & IDR_MASK] = (void *)bitmap; rcu_assign_pointer(pa[0]->ary[idr_id & IDR_MASK],
(void *)bitmap);
pa[0]->count++; pa[0]->count++;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment