* [PATCH net-next 0/3] Few minor BPF helper improvements
@ 2016-09-22 23:28 Daniel Borkmann
2016-09-22 23:28 ` [PATCH net-next 1/3] bpf: use skb_to_full_sk helper in bpf_skb_under_cgroup Daniel Borkmann
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Daniel Borkmann @ 2016-09-22 23:28 UTC (permalink / raw)
To: davem; +Cc: alexei.starovoitov, netdev, Daniel Borkmann
Just a few minor improvements around BPF helpers, first one is a
fix but given this late stage and that it's not really a critical
one, I think net-next is just fine. For details please see the
individual patches.
Thanks!
Daniel Borkmann (3):
bpf: use skb_to_full_sk helper in bpf_skb_under_cgroup
bpf: use bpf_get_smp_processor_id_proto instead of raw one
bpf: add helper to invalidate hash
include/uapi/linux/bpf.h | 7 +++++++
net/core/filter.c | 22 +++++++++++++++++++++-
2 files changed, 28 insertions(+), 1 deletion(-)
--
1.9.3
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH net-next 1/3] bpf: use skb_to_full_sk helper in bpf_skb_under_cgroup
2016-09-22 23:28 [PATCH net-next 0/3] Few minor BPF helper improvements Daniel Borkmann
@ 2016-09-22 23:28 ` Daniel Borkmann
2016-09-22 23:28 ` [PATCH net-next 2/3] bpf: use bpf_get_smp_processor_id_proto instead of raw one Daniel Borkmann
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Daniel Borkmann @ 2016-09-22 23:28 UTC (permalink / raw)
To: davem; +Cc: alexei.starovoitov, netdev, Daniel Borkmann
We need to use skb_to_full_sk() helper introduced in commit bd5eb35f16a9
("xfrm: take care of request sockets") as otherwise we miss tcp synack
messages, since ownership is on request socket and therefore it would
miss the sk_fullsock() check. Use skb_to_full_sk() as also done similarly
in the bpf_get_cgroup_classid() helper via 2309236c13fe ("cls_cgroup:
get sk_classid only from full sockets") fix to not let this fall through.
Fixes: 4a482f34afcc ("cgroup: bpf: Add bpf_skb_in_cgroup_proto")
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@kernel.org>
---
net/core/filter.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/net/core/filter.c b/net/core/filter.c
index 0920c2a..e5d9977 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -2408,7 +2408,7 @@ BPF_CALL_3(bpf_skb_under_cgroup, struct sk_buff *, skb, struct bpf_map *, map,
struct cgroup *cgrp;
struct sock *sk;
- sk = skb->sk;
+ sk = skb_to_full_sk(skb);
if (!sk || !sk_fullsock(sk))
return -ENOENT;
if (unlikely(idx >= array->map.max_entries))
--
1.9.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH net-next 2/3] bpf: use bpf_get_smp_processor_id_proto instead of raw one
2016-09-22 23:28 [PATCH net-next 0/3] Few minor BPF helper improvements Daniel Borkmann
2016-09-22 23:28 ` [PATCH net-next 1/3] bpf: use skb_to_full_sk helper in bpf_skb_under_cgroup Daniel Borkmann
@ 2016-09-22 23:28 ` Daniel Borkmann
2016-09-22 23:28 ` [PATCH net-next 3/3] bpf: add helper to invalidate hash Daniel Borkmann
2016-09-23 12:24 ` [PATCH net-next 0/3] Few minor BPF helper improvements David Miller
3 siblings, 0 replies; 5+ messages in thread
From: Daniel Borkmann @ 2016-09-22 23:28 UTC (permalink / raw)
To: davem; +Cc: alexei.starovoitov, netdev, Daniel Borkmann
Same motivation as in commit 80b48c445797 ("bpf: don't use raw processor
id in generic helper"), but this time for XDP typed programs. Thus, allow
for preemption checks when we have DEBUG_PREEMPT enabled, and otherwise
use the raw variant.
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@kernel.org>
---
net/core/filter.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/net/core/filter.c b/net/core/filter.c
index e5d9977..acf84fb 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -2551,6 +2551,8 @@ xdp_func_proto(enum bpf_func_id func_id)
switch (func_id) {
case BPF_FUNC_perf_event_output:
return &bpf_xdp_event_output_proto;
+ case BPF_FUNC_get_smp_processor_id:
+ return &bpf_get_smp_processor_id_proto;
default:
return sk_filter_func_proto(func_id);
}
--
1.9.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH net-next 3/3] bpf: add helper to invalidate hash
2016-09-22 23:28 [PATCH net-next 0/3] Few minor BPF helper improvements Daniel Borkmann
2016-09-22 23:28 ` [PATCH net-next 1/3] bpf: use skb_to_full_sk helper in bpf_skb_under_cgroup Daniel Borkmann
2016-09-22 23:28 ` [PATCH net-next 2/3] bpf: use bpf_get_smp_processor_id_proto instead of raw one Daniel Borkmann
@ 2016-09-22 23:28 ` Daniel Borkmann
2016-09-23 12:24 ` [PATCH net-next 0/3] Few minor BPF helper improvements David Miller
3 siblings, 0 replies; 5+ messages in thread
From: Daniel Borkmann @ 2016-09-22 23:28 UTC (permalink / raw)
To: davem; +Cc: alexei.starovoitov, netdev, Daniel Borkmann
Add a small helper that complements 36bbef52c7eb ("bpf: direct packet
write and access for helpers for clsact progs") for invalidating the
current skb->hash after mangling on headers via direct packet write.
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@kernel.org>
---
include/uapi/linux/bpf.h | 7 +++++++
net/core/filter.c | 18 ++++++++++++++++++
2 files changed, 25 insertions(+)
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index e07432b..f09c70b 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -419,6 +419,13 @@ enum bpf_func_id {
*/
BPF_FUNC_csum_update,
+ /**
+ * bpf_set_hash_invalid(skb)
+ * Invalidate current skb>hash.
+ * @skb: pointer to skb
+ */
+ BPF_FUNC_set_hash_invalid,
+
__BPF_FUNC_MAX_ID,
};
diff --git a/net/core/filter.c b/net/core/filter.c
index acf84fb..00351cd 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -1777,6 +1777,22 @@ static const struct bpf_func_proto bpf_get_hash_recalc_proto = {
.arg1_type = ARG_PTR_TO_CTX,
};
+BPF_CALL_1(bpf_set_hash_invalid, struct sk_buff *, skb)
+{
+ /* After all direct packet write, this can be used once for
+ * triggering a lazy recalc on next skb_get_hash() invocation.
+ */
+ skb_clear_hash(skb);
+ return 0;
+}
+
+static const struct bpf_func_proto bpf_set_hash_invalid_proto = {
+ .func = bpf_set_hash_invalid,
+ .gpl_only = false,
+ .ret_type = RET_INTEGER,
+ .arg1_type = ARG_PTR_TO_CTX,
+};
+
BPF_CALL_3(bpf_skb_vlan_push, struct sk_buff *, skb, __be16, vlan_proto,
u16, vlan_tci)
{
@@ -2534,6 +2550,8 @@ tc_cls_act_func_proto(enum bpf_func_id func_id)
return &bpf_get_route_realm_proto;
case BPF_FUNC_get_hash_recalc:
return &bpf_get_hash_recalc_proto;
+ case BPF_FUNC_set_hash_invalid:
+ return &bpf_set_hash_invalid_proto;
case BPF_FUNC_perf_event_output:
return &bpf_skb_event_output_proto;
case BPF_FUNC_get_smp_processor_id:
--
1.9.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net-next 0/3] Few minor BPF helper improvements
2016-09-22 23:28 [PATCH net-next 0/3] Few minor BPF helper improvements Daniel Borkmann
` (2 preceding siblings ...)
2016-09-22 23:28 ` [PATCH net-next 3/3] bpf: add helper to invalidate hash Daniel Borkmann
@ 2016-09-23 12:24 ` David Miller
3 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2016-09-23 12:24 UTC (permalink / raw)
To: daniel; +Cc: alexei.starovoitov, netdev
From: Daniel Borkmann <daniel@iogearbox.net>
Date: Fri, 23 Sep 2016 01:28:34 +0200
> Just a few minor improvements around BPF helpers, first one is a
> fix but given this late stage and that it's not really a critical
> one, I think net-next is just fine. For details please see the
> individual patches.
Series applied, thanks.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-09-23 12:24 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-22 23:28 [PATCH net-next 0/3] Few minor BPF helper improvements Daniel Borkmann
2016-09-22 23:28 ` [PATCH net-next 1/3] bpf: use skb_to_full_sk helper in bpf_skb_under_cgroup Daniel Borkmann
2016-09-22 23:28 ` [PATCH net-next 2/3] bpf: use bpf_get_smp_processor_id_proto instead of raw one Daniel Borkmann
2016-09-22 23:28 ` [PATCH net-next 3/3] bpf: add helper to invalidate hash Daniel Borkmann
2016-09-23 12:24 ` [PATCH net-next 0/3] Few minor BPF helper improvements David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).