Skip to content

Commit 171526f

Browse files
jsitnickiAlexei Starovoitov
authored andcommitted
flow_dissector: Pull locking up from prog attach callback
Split out the part of attach callback that happens with attach/detach lock acquired. This structures the prog attach callback in a way that opens up doors for moving the locking out of flow_dissector and into generic callbacks for attaching/detaching progs to netns in subsequent patches. Signed-off-by: Jakub Sitnicki <[email protected]> Signed-off-by: Alexei Starovoitov <[email protected]> Reviewed-by: Stanislav Fomichev <[email protected]> Link: https://lore.kernel.org/bpf/[email protected]
1 parent febeb6d commit 171526f

File tree

1 file changed

+20
-20
lines changed

1 file changed

+20
-20
lines changed

net/core/flow_dissector.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,10 @@ int skb_flow_dissector_prog_query(const union bpf_attr *attr,
109109
return 0;
110110
}
111111

112-
int skb_flow_dissector_bpf_prog_attach(const union bpf_attr *attr,
113-
struct bpf_prog *prog)
112+
static int flow_dissector_bpf_prog_attach(struct net *net,
113+
struct bpf_prog *prog)
114114
{
115115
struct bpf_prog *attached;
116-
struct net *net;
117-
int ret = 0;
118-
119-
net = current->nsproxy->net_ns;
120-
mutex_lock(&flow_dissector_mutex);
121116

122117
if (net == &init_net) {
123118
/* BPF flow dissector in the root namespace overrides
@@ -130,33 +125,38 @@ int skb_flow_dissector_bpf_prog_attach(const union bpf_attr *attr,
130125
for_each_net(ns) {
131126
if (ns == &init_net)
132127
continue;
133-
if (rcu_access_pointer(ns->flow_dissector_prog)) {
134-
ret = -EEXIST;
135-
goto out;
136-
}
128+
if (rcu_access_pointer(ns->flow_dissector_prog))
129+
return -EEXIST;
137130
}
138131
} else {
139132
/* Make sure root flow dissector is not attached
140133
* when attaching to the non-root namespace.
141134
*/
142-
if (rcu_access_pointer(init_net.flow_dissector_prog)) {
143-
ret = -EEXIST;
144-
goto out;
145-
}
135+
if (rcu_access_pointer(init_net.flow_dissector_prog))
136+
return -EEXIST;
146137
}
147138

148139
attached = rcu_dereference_protected(net->flow_dissector_prog,
149140
lockdep_is_held(&flow_dissector_mutex));
150-
if (attached == prog) {
141+
if (attached == prog)
151142
/* The same program cannot be attached twice */
152-
ret = -EINVAL;
153-
goto out;
154-
}
143+
return -EINVAL;
144+
155145
rcu_assign_pointer(net->flow_dissector_prog, prog);
156146
if (attached)
157147
bpf_prog_put(attached);
158-
out:
148+
return 0;
149+
}
150+
151+
int skb_flow_dissector_bpf_prog_attach(const union bpf_attr *attr,
152+
struct bpf_prog *prog)
153+
{
154+
int ret;
155+
156+
mutex_lock(&flow_dissector_mutex);
157+
ret = flow_dissector_bpf_prog_attach(current->nsproxy->net_ns, prog);
159158
mutex_unlock(&flow_dissector_mutex);
159+
160160
return ret;
161161
}
162162

0 commit comments

Comments
 (0)