Skip to content

Commit cb21802

Browse files
lmbborkmann
authored andcommitted
bpf: sockmap: Simplify sock_map_init_proto
We can take advantage of the fact that both callers of sock_map_init_proto are holding a RCU read lock, and have verified that psock is valid. Signed-off-by: Lorenz Bauer <lmb@cloudflare.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Reviewed-by: Jakub Sitnicki <jakub@cloudflare.com> Acked-by: John Fastabend <john.fastabend@gmail.com> Link: https://lore.kernel.org/bpf/20200309111243.6982-7-lmb@cloudflare.com
1 parent f747632 commit cb21802

1 file changed

Lines changed: 4 additions & 15 deletions

File tree

‎net/core/sock_map.c‎

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -141,28 +141,17 @@ static void sock_map_unref(struct sock *sk, void *link_raw)
141141
}
142142
}
143143

144-
static int sock_map_init_proto(struct sock *sk)
144+
static int sock_map_init_proto(struct sock *sk, struct sk_psock *psock)
145145
{
146-
struct sk_psock *psock;
147146
struct proto *prot;
148147

149148
sock_owned_by_me(sk);
150149

151-
rcu_read_lock();
152-
psock = sk_psock(sk);
153-
if (unlikely(!psock)) {
154-
rcu_read_unlock();
155-
return -EINVAL;
156-
}
157-
158150
prot = tcp_bpf_get_proto(sk, psock);
159-
if (IS_ERR(prot)) {
160-
rcu_read_unlock();
151+
if (IS_ERR(prot))
161152
return PTR_ERR(prot);
162-
}
163153

164154
sk_psock_update_proto(sk, psock, prot);
165-
rcu_read_unlock();
166155
return 0;
167156
}
168157

@@ -241,7 +230,7 @@ static int sock_map_link(struct bpf_map *map, struct sk_psock_progs *progs,
241230
if (msg_parser)
242231
psock_set_prog(&psock->progs.msg_parser, msg_parser);
243232

244-
ret = sock_map_init_proto(sk);
233+
ret = sock_map_init_proto(sk, psock);
245234
if (ret < 0)
246235
goto out_drop;
247236

@@ -286,7 +275,7 @@ static int sock_map_link_no_progs(struct bpf_map *map, struct sock *sk)
286275
return -ENOMEM;
287276
}
288277

289-
ret = sock_map_init_proto(sk);
278+
ret = sock_map_init_proto(sk, psock);
290279
if (ret < 0)
291280
sk_psock_put(sk, psock);
292281
return ret;

0 commit comments

Comments
 (0)