* [PATCH net-next] cls_bpf: do eBPF invocation under non-bh RCU lock variant for maps
@ 2015-03-12 19:03 Daniel Borkmann
2015-03-12 21:26 ` Alexei Starovoitov
2015-03-12 22:34 ` David Miller
0 siblings, 2 replies; 3+ messages in thread
From: Daniel Borkmann @ 2015-03-12 19:03 UTC (permalink / raw)
To: davem; +Cc: ast, netdev, Daniel Borkmann
Currently, it is possible in cls_bpf to access eBPF maps only under
rcu_read_lock_bh() variants: while on ingress side, that is, handle_ing(),
the classifier would be called from __netif_receive_skb_core() under
rcu_read_lock(); on egress side, however, it's rcu_read_lock_bh() via
__dev_queue_xmit().
This rcu/rcu_bh mix doesn't work together with eBPF maps as they require
soley to be called under rcu_read_lock(). eBPF maps could also be shared
among various other eBPF programs (possibly even with other eBPF program
types, f.e. tracing) and user space processes, so any context is assumed.
Therefore, a possible fix for cls_bpf is to wrap/nest eBPF program
invocation under non-bh RCU lock variant.
Fixes: e2e9b6541dd4 ("cls_bpf: add initial eBPF support for programmable classifiers")
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
---
net/sched/cls_bpf.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/net/sched/cls_bpf.c b/net/sched/cls_bpf.c
index 243c9f2..5c4171c 100644
--- a/net/sched/cls_bpf.c
+++ b/net/sched/cls_bpf.c
@@ -64,8 +64,10 @@ static int cls_bpf_classify(struct sk_buff *skb, const struct tcf_proto *tp,
{
struct cls_bpf_head *head = rcu_dereference_bh(tp->root);
struct cls_bpf_prog *prog;
- int ret;
+ int ret = -1;
+ /* Needed here for accessing maps. */
+ rcu_read_lock();
list_for_each_entry_rcu(prog, &head->plist, link) {
int filter_res = BPF_PROG_RUN(prog->filter, skb);
@@ -80,10 +82,11 @@ static int cls_bpf_classify(struct sk_buff *skb, const struct tcf_proto *tp,
if (ret < 0)
continue;
- return ret;
+ break;
}
+ rcu_read_unlock();
- return -1;
+ return ret;
}
static bool cls_bpf_is_ebpf(const struct cls_bpf_prog *prog)
--
1.9.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] cls_bpf: do eBPF invocation under non-bh RCU lock variant for maps
2015-03-12 19:03 [PATCH net-next] cls_bpf: do eBPF invocation under non-bh RCU lock variant for maps Daniel Borkmann
@ 2015-03-12 21:26 ` Alexei Starovoitov
2015-03-12 22:34 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: Alexei Starovoitov @ 2015-03-12 21:26 UTC (permalink / raw)
To: Daniel Borkmann, davem; +Cc: netdev
On 3/12/15 12:03 PM, Daniel Borkmann wrote:
> Currently, it is possible in cls_bpf to access eBPF maps only under
> rcu_read_lock_bh() variants: while on ingress side, that is, handle_ing(),
> the classifier would be called from __netif_receive_skb_core() under
> rcu_read_lock(); on egress side, however, it's rcu_read_lock_bh() via
> __dev_queue_xmit().
>
> This rcu/rcu_bh mix doesn't work together with eBPF maps as they require
> soley to be called under rcu_read_lock(). eBPF maps could also be shared
> among various other eBPF programs (possibly even with other eBPF program
> types, f.e. tracing) and user space processes, so any context is assumed.
>
> Therefore, a possible fix for cls_bpf is to wrap/nest eBPF program
> invocation under non-bh RCU lock variant.
>
> Fixes: e2e9b6541dd4 ("cls_bpf: add initial eBPF support for programmable classifiers")
> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@plumgrid.com>
thanks!
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net-next] cls_bpf: do eBPF invocation under non-bh RCU lock variant for maps
2015-03-12 19:03 [PATCH net-next] cls_bpf: do eBPF invocation under non-bh RCU lock variant for maps Daniel Borkmann
2015-03-12 21:26 ` Alexei Starovoitov
@ 2015-03-12 22:34 ` David Miller
1 sibling, 0 replies; 3+ messages in thread
From: David Miller @ 2015-03-12 22:34 UTC (permalink / raw)
To: daniel; +Cc: ast, netdev
From: Daniel Borkmann <daniel@iogearbox.net>
Date: Thu, 12 Mar 2015 20:03:12 +0100
> Currently, it is possible in cls_bpf to access eBPF maps only under
> rcu_read_lock_bh() variants: while on ingress side, that is, handle_ing(),
> the classifier would be called from __netif_receive_skb_core() under
> rcu_read_lock(); on egress side, however, it's rcu_read_lock_bh() via
> __dev_queue_xmit().
>
> This rcu/rcu_bh mix doesn't work together with eBPF maps as they require
> soley to be called under rcu_read_lock(). eBPF maps could also be shared
> among various other eBPF programs (possibly even with other eBPF program
> types, f.e. tracing) and user space processes, so any context is assumed.
>
> Therefore, a possible fix for cls_bpf is to wrap/nest eBPF program
> invocation under non-bh RCU lock variant.
>
> Fixes: e2e9b6541dd4 ("cls_bpf: add initial eBPF support for programmable classifiers")
> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Applied, thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-03-12 22:34 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-12 19:03 [PATCH net-next] cls_bpf: do eBPF invocation under non-bh RCU lock variant for maps Daniel Borkmann
2015-03-12 21:26 ` Alexei Starovoitov
2015-03-12 22:34 ` David Miller
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.