Skip to content

Commit 8f6fd83

Browse files
bcopelandjmberg-intel
authored andcommitted
rhashtable: accept GFP flags in rhashtable_walk_init
In certain cases, the 802.11 mesh pathtable code wants to iterate over all of the entries in the forwarding table from the receive path, which is inside an RCU read-side critical section. Enable walks inside atomic sections by allowing GFP_ATOMIC allocations for the walker state. Change all existing callsites to pass in GFP_KERNEL. Acked-by: Thomas Graf <[email protected]> Signed-off-by: Bob Copeland <[email protected]> [also adjust gfs2/glock.c and rhashtable tests] Signed-off-by: Johannes Berg <[email protected]>
1 parent 947c2a0 commit 8f6fd83

File tree

8 files changed

+17
-11
lines changed

8 files changed

+17
-11
lines changed

fs/gfs2/glock.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1913,7 +1913,7 @@ static int gfs2_glocks_open(struct inode *inode, struct file *file)
19131913
if (seq->buf)
19141914
seq->size = GFS2_SEQ_GOODSIZE;
19151915
gi->gl = NULL;
1916-
ret = rhashtable_walk_init(&gl_hash_table, &gi->hti);
1916+
ret = rhashtable_walk_init(&gl_hash_table, &gi->hti, GFP_KERNEL);
19171917
}
19181918
return ret;
19191919
}
@@ -1941,7 +1941,7 @@ static int gfs2_glstats_open(struct inode *inode, struct file *file)
19411941
if (seq->buf)
19421942
seq->size = GFS2_SEQ_GOODSIZE;
19431943
gi->gl = NULL;
1944-
ret = rhashtable_walk_init(&gl_hash_table, &gi->hti);
1944+
ret = rhashtable_walk_init(&gl_hash_table, &gi->hti, GFP_KERNEL);
19451945
}
19461946
return ret;
19471947
}

include/linux/rhashtable.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ struct bucket_table *rhashtable_insert_slow(struct rhashtable *ht,
346346
struct bucket_table *old_tbl);
347347
int rhashtable_insert_rehash(struct rhashtable *ht, struct bucket_table *tbl);
348348

349-
int rhashtable_walk_init(struct rhashtable *ht, struct rhashtable_iter *iter);
349+
int rhashtable_walk_init(struct rhashtable *ht, struct rhashtable_iter *iter,
350+
gfp_t gfp);
350351
void rhashtable_walk_exit(struct rhashtable_iter *iter);
351352
int rhashtable_walk_start(struct rhashtable_iter *iter) __acquires(RCU);
352353
void *rhashtable_walk_next(struct rhashtable_iter *iter);

lib/rhashtable.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,7 @@ EXPORT_SYMBOL_GPL(rhashtable_insert_slow);
487487
* rhashtable_walk_init - Initialise an iterator
488488
* @ht: Table to walk over
489489
* @iter: Hash table Iterator
490+
* @gfp: GFP flags for allocations
490491
*
491492
* This function prepares a hash table walk.
492493
*
@@ -504,14 +505,15 @@ EXPORT_SYMBOL_GPL(rhashtable_insert_slow);
504505
* You must call rhashtable_walk_exit if this function returns
505506
* successfully.
506507
*/
507-
int rhashtable_walk_init(struct rhashtable *ht, struct rhashtable_iter *iter)
508+
int rhashtable_walk_init(struct rhashtable *ht, struct rhashtable_iter *iter,
509+
gfp_t gfp)
508510
{
509511
iter->ht = ht;
510512
iter->p = NULL;
511513
iter->slot = 0;
512514
iter->skip = 0;
513515

514-
iter->walker = kmalloc(sizeof(*iter->walker), GFP_KERNEL);
516+
iter->walker = kmalloc(sizeof(*iter->walker), gfp);
515517
if (!iter->walker)
516518
return -ENOMEM;
517519

lib/test_rhashtable.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ static void test_bucket_stats(struct rhashtable *ht)
143143
struct rhashtable_iter hti;
144144
struct rhash_head *pos;
145145

146-
err = rhashtable_walk_init(ht, &hti);
146+
err = rhashtable_walk_init(ht, &hti, GFP_KERNEL);
147147
if (err) {
148148
pr_warn("Test failed: allocation error");
149149
return;

net/ipv6/ila/ila_xlat.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,8 @@ static int ila_nl_dump_start(struct netlink_callback *cb)
501501
struct ila_net *ilan = net_generic(net, ila_net_id);
502502
struct ila_dump_iter *iter = (struct ila_dump_iter *)cb->args;
503503

504-
return rhashtable_walk_init(&ilan->rhash_table, &iter->rhiter);
504+
return rhashtable_walk_init(&ilan->rhash_table, &iter->rhiter,
505+
GFP_KERNEL);
505506
}
506507

507508
static int ila_nl_dump_done(struct netlink_callback *cb)

net/netfilter/nft_hash.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ static void nft_hash_walk(const struct nft_ctx *ctx, const struct nft_set *set,
192192
u8 genmask = nft_genmask_cur(read_pnet(&set->pnet));
193193
int err;
194194

195-
err = rhashtable_walk_init(&priv->ht, &hti);
195+
err = rhashtable_walk_init(&priv->ht, &hti, GFP_KERNEL);
196196
iter->err = err;
197197
if (err)
198198
return;
@@ -248,7 +248,7 @@ static void nft_hash_gc(struct work_struct *work)
248248
priv = container_of(work, struct nft_hash, gc_work.work);
249249
set = nft_set_container_of(priv);
250250

251-
err = rhashtable_walk_init(&priv->ht, &hti);
251+
err = rhashtable_walk_init(&priv->ht, &hti, GFP_KERNEL);
252252
if (err)
253253
goto schedule;
254254

net/netlink/af_netlink.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2343,7 +2343,8 @@ static int netlink_walk_start(struct nl_seq_iter *iter)
23432343
{
23442344
int err;
23452345

2346-
err = rhashtable_walk_init(&nl_table[iter->link].hash, &iter->hti);
2346+
err = rhashtable_walk_init(&nl_table[iter->link].hash, &iter->hti,
2347+
GFP_KERNEL);
23472348
if (err) {
23482349
iter->link = MAX_LINKS;
23492350
return err;

net/sctp/proc.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,8 @@ static int sctp_transport_walk_start(struct seq_file *seq)
319319
struct sctp_ht_iter *iter = seq->private;
320320
int err;
321321

322-
err = rhashtable_walk_init(&sctp_transport_hashtable, &iter->hti);
322+
err = rhashtable_walk_init(&sctp_transport_hashtable, &iter->hti,
323+
GFP_KERNEL);
323324
if (err)
324325
return err;
325326

0 commit comments

Comments
 (0)