diff options
author | Daniel Borkmann <daniel@iogearbox.net> | 2015-10-29 09:58:08 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2015-11-02 22:48:39 -0500 |
commit | e9d8afa90b789b07d414637ab557d169d6b2b84e (patch) | |
tree | 534e0a4721d7d9af501b4bdf10757a517109c3af | |
parent | c210129760a010b555372ef74f4e1a46d4eb8a22 (diff) |
bpf: consolidate bpf_prog_put{, _rcu} dismantle paths
We currently have duplicated cleanup code in bpf_prog_put() and
bpf_prog_put_rcu() cleanup paths. Back then we decided that it was
not worth it to make it a common helper called by both, but with
the recent addition of resource charging, we could have avoided
the fix in commit ac00737f4e81 ("bpf: Need to call bpf_prog_uncharge_memlock
from bpf_prog_put") if we would have had only a single, common path.
We can simplify it further by assigning aux->prog only once during
allocation time.
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | kernel/bpf/core.c | 3 | ||||
-rw-r--r-- | kernel/bpf/syscall.c | 15 |
2 files changed, 7 insertions, 11 deletions
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c index 80864712d2c4..334b1bdd572c 100644 --- a/kernel/bpf/core.c +++ b/kernel/bpf/core.c | |||
@@ -92,6 +92,7 @@ struct bpf_prog *bpf_prog_alloc(unsigned int size, gfp_t gfp_extra_flags) | |||
92 | 92 | ||
93 | fp->pages = size / PAGE_SIZE; | 93 | fp->pages = size / PAGE_SIZE; |
94 | fp->aux = aux; | 94 | fp->aux = aux; |
95 | fp->aux->prog = fp; | ||
95 | 96 | ||
96 | return fp; | 97 | return fp; |
97 | } | 98 | } |
@@ -116,6 +117,7 @@ struct bpf_prog *bpf_prog_realloc(struct bpf_prog *fp_old, unsigned int size, | |||
116 | 117 | ||
117 | memcpy(fp, fp_old, fp_old->pages * PAGE_SIZE); | 118 | memcpy(fp, fp_old, fp_old->pages * PAGE_SIZE); |
118 | fp->pages = size / PAGE_SIZE; | 119 | fp->pages = size / PAGE_SIZE; |
120 | fp->aux->prog = fp; | ||
119 | 121 | ||
120 | /* We keep fp->aux from fp_old around in the new | 122 | /* We keep fp->aux from fp_old around in the new |
121 | * reallocated structure. | 123 | * reallocated structure. |
@@ -726,7 +728,6 @@ void bpf_prog_free(struct bpf_prog *fp) | |||
726 | struct bpf_prog_aux *aux = fp->aux; | 728 | struct bpf_prog_aux *aux = fp->aux; |
727 | 729 | ||
728 | INIT_WORK(&aux->work, bpf_prog_free_deferred); | 730 | INIT_WORK(&aux->work, bpf_prog_free_deferred); |
729 | aux->prog = fp; | ||
730 | schedule_work(&aux->work); | 731 | schedule_work(&aux->work); |
731 | } | 732 | } |
732 | EXPORT_SYMBOL_GPL(bpf_prog_free); | 733 | EXPORT_SYMBOL_GPL(bpf_prog_free); |
diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 3fff82ca68fa..d7783cb04d86 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c | |||
@@ -513,7 +513,7 @@ static void bpf_prog_uncharge_memlock(struct bpf_prog *prog) | |||
513 | free_uid(user); | 513 | free_uid(user); |
514 | } | 514 | } |
515 | 515 | ||
516 | static void __prog_put_rcu(struct rcu_head *rcu) | 516 | static void __prog_put_common(struct rcu_head *rcu) |
517 | { | 517 | { |
518 | struct bpf_prog_aux *aux = container_of(rcu, struct bpf_prog_aux, rcu); | 518 | struct bpf_prog_aux *aux = container_of(rcu, struct bpf_prog_aux, rcu); |
519 | 519 | ||
@@ -525,19 +525,14 @@ static void __prog_put_rcu(struct rcu_head *rcu) | |||
525 | /* version of bpf_prog_put() that is called after a grace period */ | 525 | /* version of bpf_prog_put() that is called after a grace period */ |
526 | void bpf_prog_put_rcu(struct bpf_prog *prog) | 526 | void bpf_prog_put_rcu(struct bpf_prog *prog) |
527 | { | 527 | { |
528 | if (atomic_dec_and_test(&prog->aux->refcnt)) { | 528 | if (atomic_dec_and_test(&prog->aux->refcnt)) |
529 | prog->aux->prog = prog; | 529 | call_rcu(&prog->aux->rcu, __prog_put_common); |
530 | call_rcu(&prog->aux->rcu, __prog_put_rcu); | ||
531 | } | ||
532 | } | 530 | } |
533 | 531 | ||
534 | void bpf_prog_put(struct bpf_prog *prog) | 532 | void bpf_prog_put(struct bpf_prog *prog) |
535 | { | 533 | { |
536 | if (atomic_dec_and_test(&prog->aux->refcnt)) { | 534 | if (atomic_dec_and_test(&prog->aux->refcnt)) |
537 | free_used_maps(prog->aux); | 535 | __prog_put_common(&prog->aux->rcu); |
538 | bpf_prog_uncharge_memlock(prog); | ||
539 | bpf_prog_free(prog); | ||
540 | } | ||
541 | } | 536 | } |
542 | EXPORT_SYMBOL_GPL(bpf_prog_put); | 537 | EXPORT_SYMBOL_GPL(bpf_prog_put); |
543 | 538 | ||