Skip to content

Commit 0db4941

Browse files
Fushuai WangMartin KaFai Lau
authored andcommitted
bpf: Use rcu_read_lock_dont_migrate in bpf_sk_storage.c
Use rcu_read_lock_dont_migrate() and rcu_read_unlock_migrate() in bpf_sk_storage.c to obtain better performance when PREEMPT_RCU is not enabled. Signed-off-by: Fushuai Wang <[email protected]> Signed-off-by: Martin KaFai Lau <[email protected]> Link: https://patch.msgid.link/[email protected]
1 parent de73422 commit 0db4941

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

net/core/bpf_sk_storage.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,14 @@ void bpf_sk_storage_free(struct sock *sk)
5050
{
5151
struct bpf_local_storage *sk_storage;
5252

53-
migrate_disable();
54-
rcu_read_lock();
53+
rcu_read_lock_dont_migrate();
5554
sk_storage = rcu_dereference(sk->sk_bpf_storage);
5655
if (!sk_storage)
5756
goto out;
5857

5958
bpf_local_storage_destroy(sk_storage);
6059
out:
61-
rcu_read_unlock();
62-
migrate_enable();
60+
rcu_read_unlock_migrate();
6361
}
6462

6563
static void bpf_sk_storage_map_free(struct bpf_map *map)
@@ -161,8 +159,7 @@ int bpf_sk_storage_clone(const struct sock *sk, struct sock *newsk)
161159

162160
RCU_INIT_POINTER(newsk->sk_bpf_storage, NULL);
163161

164-
migrate_disable();
165-
rcu_read_lock();
162+
rcu_read_lock_dont_migrate();
166163
sk_storage = rcu_dereference(sk->sk_bpf_storage);
167164

168165
if (!sk_storage || hlist_empty(&sk_storage->list))
@@ -213,8 +210,7 @@ int bpf_sk_storage_clone(const struct sock *sk, struct sock *newsk)
213210
}
214211

215212
out:
216-
rcu_read_unlock();
217-
migrate_enable();
213+
rcu_read_unlock_migrate();
218214

219215
/* In case of an error, don't free anything explicitly here, the
220216
* caller is responsible to call bpf_sk_storage_free.

0 commit comments

Comments
 (0)