Blame SOURCES/rhbz1643997.0019-PR23829-fallback-defines-__BPF_FUNC_MAPPER-and-BPF_J.patch

cab4ad
From 0d45550a184cc5a9f10187a97b9ef8dc7fa13f31 Mon Sep 17 00:00:00 2001
cab4ad
From: Serhei Makarov <smakarov@redhat.com>
cab4ad
Date: Fri, 2 Nov 2018 16:49:23 -0400
cab4ad
Subject: [PATCH 19/32] PR23829 :: fallback defines __BPF_FUNC_MAPPER and
cab4ad
 BPF_J{LT,LE,SLT,SLE} for older kernels
cab4ad
cab4ad
---
cab4ad
 bpf-base.cxx   | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
cab4ad
 bpf-internal.h | 11 +++++++++++
cab4ad
 2 files changed, 70 insertions(+)
cab4ad
cab4ad
diff --git a/bpf-base.cxx b/bpf-base.cxx
cab4ad
index 277927b72..210efa9aa 100644
cab4ad
--- a/bpf-base.cxx
cab4ad
+++ b/bpf-base.cxx
cab4ad
@@ -140,6 +140,65 @@ is_commutative(opcode code)
cab4ad
 std::map<unsigned, const char *> bpf_func_name_map;
cab4ad
 std::map<std::string, bpf_func_id> bpf_func_id_map;
cab4ad
 
cab4ad
+/* PR23829: On older kernels, bpf.h does not define __BPF_FUNC_MAPPER.
cab4ad
+   As a fallback, use the *earliest* __BPF_FUNC_MAPPER, so stapbpf
cab4ad
+   will not try helpers that only exist on subsequent kernels.
cab4ad
+
cab4ad
+   TODO: This isn't perfect since even older kernels don't have
cab4ad
+   some of these helpers.
cab4ad
+
cab4ad
+   XXX: Note the build limitation in that SystemTap must be compiled
cab4ad
+   against a recent kernel to be able to use the helpers from that
cab4ad
+   kernel. That's also the case when building against recent bpf.h
cab4ad
+   with __BPF_FUNC_MAPPER, so this workaround is not the source of the
cab4ad
+   problem. */
cab4ad
+#ifndef __BPF_FUNC_MAPPER
cab4ad
+#define __BPF_FUNC_MAPPER(FN)		\
cab4ad
+	FN(unspec),			\
cab4ad
+	FN(map_lookup_elem),		\
cab4ad
+	FN(map_update_elem),		\
cab4ad
+	FN(map_delete_elem),		\
cab4ad
+	FN(probe_read),			\
cab4ad
+	FN(ktime_get_ns),		\
cab4ad
+	FN(trace_printk),		\
cab4ad
+	FN(get_prandom_u32),		\
cab4ad
+	FN(get_smp_processor_id),	\
cab4ad
+	FN(skb_store_bytes),		\
cab4ad
+	FN(l3_csum_replace),		\
cab4ad
+	FN(l4_csum_replace),		\
cab4ad
+	FN(tail_call),			\
cab4ad
+	FN(clone_redirect),		\
cab4ad
+	FN(get_current_pid_tgid),	\
cab4ad
+	FN(get_current_uid_gid),	\
cab4ad
+	FN(get_current_comm),		\
cab4ad
+	FN(get_cgroup_classid),		\
cab4ad
+	FN(skb_vlan_push),		\
cab4ad
+	FN(skb_vlan_pop),		\
cab4ad
+	FN(skb_get_tunnel_key),		\
cab4ad
+	FN(skb_set_tunnel_key),		\
cab4ad
+	FN(perf_event_read),		\
cab4ad
+	FN(redirect),			\
cab4ad
+	FN(get_route_realm),		\
cab4ad
+	FN(perf_event_output),		\
cab4ad
+	FN(skb_load_bytes),		\
cab4ad
+	FN(get_stackid),		\
cab4ad
+	FN(csum_diff),			\
cab4ad
+	FN(skb_get_tunnel_opt),		\
cab4ad
+	FN(skb_set_tunnel_opt),		\
cab4ad
+	FN(skb_change_proto),		\
cab4ad
+	FN(skb_change_type),		\
cab4ad
+	FN(skb_under_cgroup),		\
cab4ad
+	FN(get_hash_recalc),		\
cab4ad
+	FN(get_current_task),		\
cab4ad
+	FN(probe_write_user),		\
cab4ad
+	FN(current_task_under_cgroup),	\
cab4ad
+	FN(skb_change_tail),		\
cab4ad
+	FN(skb_pull_data),		\
cab4ad
+	FN(csum_update),		\
cab4ad
+	FN(set_hash_invalid),           \
cab4ad
+
cab4ad
+#endif
cab4ad
+
cab4ad
 void
cab4ad
 init_bpf_helper_tables () // TODO call before script translation
cab4ad
 {
cab4ad
diff --git a/bpf-internal.h b/bpf-internal.h
cab4ad
index 3041bbdf5..82cba2c79 100644
cab4ad
--- a/bpf-internal.h
cab4ad
+++ b/bpf-internal.h
cab4ad
@@ -21,6 +21,17 @@ extern "C" {
cab4ad
 #include <linux/bpf.h>
cab4ad
 }
cab4ad
 
cab4ad
+/* PR23829: These eBPF opcodes were added in recent kernels, and the
cab4ad
+   following 'ad hoc' defines are only used by the embedded-code
cab4ad
+   assembler.  The code generator will convert these opcodes to
cab4ad
+   equivalent operations valid for earlier eBPF. */
cab4ad
+#ifndef BPF_JLT
cab4ad
+#define BPF_JLT		0xa0	/* LT is unsigned, '<' */
cab4ad
+#define BPF_JLE		0xb0	/* LE is unsigned, '<=' */
cab4ad
+#define BPF_JSLT	0xc0	/* SLT is signed, '<' */
cab4ad
+#define BPF_JSLE	0xd0	/* SLE is signed, '<=' */
cab4ad
+#endif
cab4ad
+
cab4ad
 struct systemtap_session;
cab4ad
 struct derived_probe;
cab4ad
 struct vardecl;
cab4ad
-- 
cab4ad
2.14.5
cab4ad