From: Mykyta Yatsenko The four owner types have the same delete code. A later patch changes how a value is deleted. One function keeps that change in one place. No functional change intended. Signed-off-by: Mykyta Yatsenko --- include/linux/bpf_local_storage.h | 2 ++ kernel/bpf/bpf_cgrp_storage.c | 8 +------- kernel/bpf/bpf_inode_storage.c | 8 +------- kernel/bpf/bpf_local_storage.c | 15 +++++++++++++++ kernel/bpf/bpf_task_storage.c | 8 +------- net/core/bpf_sk_storage.c | 8 +------- 6 files changed, 21 insertions(+), 28 deletions(-) diff --git a/include/linux/bpf_local_storage.h b/include/linux/bpf_local_storage.h index d336fc051054..ba8de9f5ec33 100644 --- a/include/linux/bpf_local_storage.h +++ b/include/linux/bpf_local_storage.h @@ -196,6 +196,8 @@ void bpf_selem_link_storage_nolock(struct bpf_local_storage *local_storage, int bpf_selem_unlink(struct bpf_local_storage_elem *selem); +int bpf_local_storage_delete(void *owner, struct bpf_local_storage_map *smap); + int bpf_selem_link_map(struct bpf_local_storage_map *smap, struct bpf_local_storage *local_storage, struct bpf_local_storage_elem *selem); diff --git a/kernel/bpf/bpf_cgrp_storage.c b/kernel/bpf/bpf_cgrp_storage.c index c76e9b0fabba..d335e2965ea8 100644 --- a/kernel/bpf/bpf_cgrp_storage.c +++ b/kernel/bpf/bpf_cgrp_storage.c @@ -83,13 +83,7 @@ static long bpf_cgrp_storage_update_elem(struct bpf_map *map, void *key, static int cgroup_storage_delete(struct cgroup *cgroup, struct bpf_map *map) { - struct bpf_local_storage_data *sdata; - - sdata = cgroup_storage_lookup(cgroup, map, false); - if (!sdata) - return -ENOENT; - - return bpf_selem_unlink(SELEM(sdata)); + return bpf_local_storage_delete(cgroup, (struct bpf_local_storage_map *)map); } static long bpf_cgrp_storage_delete_elem(struct bpf_map *map, void *key) diff --git a/kernel/bpf/bpf_inode_storage.c b/kernel/bpf/bpf_inode_storage.c index f9e81060c1f4..07ba08707979 100644 --- a/kernel/bpf/bpf_inode_storage.c +++ b/kernel/bpf/bpf_inode_storage.c @@ -104,13 +104,7 @@ static long bpf_fd_inode_storage_update_elem(struct bpf_map *map, void *key, static int inode_storage_delete(struct inode *inode, struct bpf_map *map) { - struct bpf_local_storage_data *sdata; - - sdata = inode_storage_lookup(inode, map, false); - if (!sdata) - return -ENOENT; - - return bpf_selem_unlink(SELEM(sdata)); + return bpf_local_storage_delete(inode, (struct bpf_local_storage_map *)map); } static long bpf_fd_inode_storage_delete_elem(struct bpf_map *map, void *key) diff --git a/kernel/bpf/bpf_local_storage.c b/kernel/bpf/bpf_local_storage.c index 6f884c9fdcea..2d2a627360fe 100644 --- a/kernel/bpf/bpf_local_storage.c +++ b/kernel/bpf/bpf_local_storage.c @@ -356,6 +356,21 @@ int bpf_selem_unlink(struct bpf_local_storage_elem *selem) return err; } +int bpf_local_storage_delete(void *owner, struct bpf_local_storage_map *smap) +{ + struct bpf_local_storage __rcu **owner_ptr = owner_storage(smap, owner); + struct bpf_local_storage *local_storage; + struct bpf_local_storage_data *sdata; + + /* An inode can have no LSM blob, so no storage pointer */ + local_storage = owner_ptr ? rcu_dereference_check(*owner_ptr, bpf_rcu_lock_held()) : NULL; + sdata = local_storage ? bpf_local_storage_lookup(local_storage, smap, false) : NULL; + if (!sdata) + return -ENOENT; + + return bpf_selem_unlink(SELEM(sdata)); +} + /* * Unlink an selem from map and local storage with lockless fallback if callers * are racing or rqspinlock returns error. It should only be called by diff --git a/kernel/bpf/bpf_task_storage.c b/kernel/bpf/bpf_task_storage.c index 4b342be29eac..1f73292755b4 100644 --- a/kernel/bpf/bpf_task_storage.c +++ b/kernel/bpf/bpf_task_storage.c @@ -128,13 +128,7 @@ static long bpf_pid_task_storage_update_elem(struct bpf_map *map, void *key, static int task_storage_delete(struct task_struct *task, struct bpf_map *map) { - struct bpf_local_storage_data *sdata; - - sdata = task_storage_lookup(task, map, false); - if (!sdata) - return -ENOENT; - - return bpf_selem_unlink(SELEM(sdata)); + return bpf_local_storage_delete(task, (struct bpf_local_storage_map *)map); } static long bpf_pid_task_storage_delete_elem(struct bpf_map *map, void *key) diff --git a/net/core/bpf_sk_storage.c b/net/core/bpf_sk_storage.c index 1c59300af05c..a838be80ebbd 100644 --- a/net/core/bpf_sk_storage.c +++ b/net/core/bpf_sk_storage.c @@ -34,13 +34,7 @@ bpf_sk_storage_lookup(struct sock *sk, struct bpf_map *map, bool cacheit_lockit) static int bpf_sk_storage_del(struct sock *sk, struct bpf_map *map) { - struct bpf_local_storage_data *sdata; - - sdata = bpf_sk_storage_lookup(sk, map, false); - if (!sdata) - return -ENOENT; - - return bpf_selem_unlink(SELEM(sdata)); + return bpf_local_storage_delete(sk, (struct bpf_local_storage_map *)map); } /* Called by __sk_destruct() & bpf_sk_storage_clone() */ -- 2.53.1-Meta