Skip to content

Commit 1b1a01d

Browse files
Hou TaoAlexei Starovoitov
authored andcommitted
bpf: Remove migrate_{disable|enable} from LPM trie
Both bpf program and bpf syscall may invoke ->update or ->delete operation for LPM trie. For bpf program, its running context has already disabled migration explicitly through (migrate_disable()) or implicitly through (preempt_disable() or disable irq). For bpf syscall, the migration is disabled through the use of bpf_disable_instrumentation() before invoking the corresponding map operation callback. Therefore, it is safe to remove the migrate_{disable|enable){} pair from LPM trie. Signed-off-by: Hou Tao <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Alexei Starovoitov <[email protected]>
1 parent bfaac2a commit 1b1a01d

File tree

1 file changed

+4
-16
lines changed

1 file changed

+4
-16
lines changed

kernel/bpf/lpm_trie.c

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -289,16 +289,11 @@ static void *trie_lookup_elem(struct bpf_map *map, void *_key)
289289
}
290290

291291
static struct lpm_trie_node *lpm_trie_node_alloc(struct lpm_trie *trie,
292-
const void *value,
293-
bool disable_migration)
292+
const void *value)
294293
{
295294
struct lpm_trie_node *node;
296295

297-
if (disable_migration)
298-
migrate_disable();
299296
node = bpf_mem_cache_alloc(&trie->ma);
300-
if (disable_migration)
301-
migrate_enable();
302297

303298
if (!node)
304299
return NULL;
@@ -342,10 +337,8 @@ static long trie_update_elem(struct bpf_map *map,
342337
if (key->prefixlen > trie->max_prefixlen)
343338
return -EINVAL;
344339

345-
/* Allocate and fill a new node. Need to disable migration before
346-
* invoking bpf_mem_cache_alloc().
347-
*/
348-
new_node = lpm_trie_node_alloc(trie, value, true);
340+
/* Allocate and fill a new node */
341+
new_node = lpm_trie_node_alloc(trie, value);
349342
if (!new_node)
350343
return -ENOMEM;
351344

@@ -425,8 +418,7 @@ static long trie_update_elem(struct bpf_map *map,
425418
goto out;
426419
}
427420

428-
/* migration is disabled within the locked scope */
429-
im_node = lpm_trie_node_alloc(trie, NULL, false);
421+
im_node = lpm_trie_node_alloc(trie, NULL);
430422
if (!im_node) {
431423
trie->n_entries--;
432424
ret = -ENOMEM;
@@ -452,11 +444,9 @@ static long trie_update_elem(struct bpf_map *map,
452444
out:
453445
raw_spin_unlock_irqrestore(&trie->lock, irq_flags);
454446

455-
migrate_disable();
456447
if (ret)
457448
bpf_mem_cache_free(&trie->ma, new_node);
458449
bpf_mem_cache_free_rcu(&trie->ma, free_node);
459-
migrate_enable();
460450

461451
return ret;
462452
}
@@ -555,10 +545,8 @@ static long trie_delete_elem(struct bpf_map *map, void *_key)
555545
out:
556546
raw_spin_unlock_irqrestore(&trie->lock, irq_flags);
557547

558-
migrate_disable();
559548
bpf_mem_cache_free_rcu(&trie->ma, free_parent);
560549
bpf_mem_cache_free_rcu(&trie->ma, free_node);
561-
migrate_enable();
562550

563551
return ret;
564552
}

0 commit comments

Comments
 (0)