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

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