Commit 3219b3b7456d5cf15ba7b1fe7b1bcf15ce8840e2
Committed by
Linus Torvalds
1 parent
944ca05c7b
Exists in
master
and in
20 other branches
idr: make idr_get_new* rcu-safe
Make the idr_get_new* routines rcu-safe. Signed-off-by: Nadia Derbey <Nadia.Derbey@bull.net> Reviewed-by: "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: Rik van Riel <riel@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 1 changed file with 9 additions and 5 deletions Side-by-side Diff
lib/idr.c
... | ... | @@ -6,6 +6,8 @@ |
6 | 6 | * Modified by George Anzinger to reuse immediately and to use |
7 | 7 | * find bit instructions. Also removed _irq on spinlocks. |
8 | 8 | * |
9 | + * Modified by Nadia Derbey to make it RCU safe. | |
10 | + * | |
9 | 11 | * Small id to pointer translation service. |
10 | 12 | * |
11 | 13 | * It uses a radix tree like structure as a sparse array indexed |
... | ... | @@ -96,7 +98,7 @@ |
96 | 98 | * @gfp_mask: memory allocation flags |
97 | 99 | * |
98 | 100 | * This function should be called prior to locking and calling the |
99 | - * following function. It preallocates enough memory to satisfy | |
101 | + * idr_get_new* functions. It preallocates enough memory to satisfy | |
100 | 102 | * the worst possible allocation. |
101 | 103 | * |
102 | 104 | * If the system is REALLY out of memory this function returns 0, |
... | ... | @@ -170,7 +172,7 @@ |
170 | 172 | new = get_from_free_list(idp); |
171 | 173 | if (!new) |
172 | 174 | return -1; |
173 | - p->ary[m] = new; | |
175 | + rcu_assign_pointer(p->ary[m], new); | |
174 | 176 | p->count++; |
175 | 177 | } |
176 | 178 | pa[l--] = p; |
... | ... | @@ -226,7 +228,7 @@ |
226 | 228 | __set_bit(0, &new->bitmap); |
227 | 229 | p = new; |
228 | 230 | } |
229 | - idp->top = p; | |
231 | + rcu_assign_pointer(idp->top, p); | |
230 | 232 | idp->layers = layers; |
231 | 233 | v = sub_alloc(idp, &id, pa); |
232 | 234 | if (v == IDR_NEED_TO_GROW) |
... | ... | @@ -245,7 +247,8 @@ |
245 | 247 | * Successfully found an empty slot. Install the user |
246 | 248 | * pointer and mark the slot full. |
247 | 249 | */ |
248 | - pa[0]->ary[id & IDR_MASK] = (struct idr_layer *)ptr; | |
250 | + rcu_assign_pointer(pa[0]->ary[id & IDR_MASK], | |
251 | + (struct idr_layer *)ptr); | |
249 | 252 | pa[0]->count++; |
250 | 253 | idr_mark_full(pa, id); |
251 | 254 | } |
... | ... | @@ -710,7 +713,8 @@ |
710 | 713 | return -EAGAIN; |
711 | 714 | |
712 | 715 | memset(bitmap, 0, sizeof(struct ida_bitmap)); |
713 | - pa[0]->ary[idr_id & IDR_MASK] = (void *)bitmap; | |
716 | + rcu_assign_pointer(pa[0]->ary[idr_id & IDR_MASK], | |
717 | + (void *)bitmap); | |
714 | 718 | pa[0]->count++; |
715 | 719 | } |
716 | 720 |