Skip to content

Commit

Permalink
Share bpf maps internally and remove pinning / bpffs requirement (#1251)
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaelroquetto authored Oct 15, 2024
1 parent ac3b137 commit c9d2647
Show file tree
Hide file tree
Showing 50 changed files with 152 additions and 360 deletions.
3 changes: 2 additions & 1 deletion bpf/bpf_dbg.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "vmlinux.h"
#include "bpf_core_read.h"
#include "pin_internal.h"

#ifdef BPF_DEBUG

Expand All @@ -26,7 +27,7 @@ typedef struct log_info {
struct {
__uint(type, BPF_MAP_TYPE_RINGBUF);
__uint(max_entries, 1 << 12);
__uint(pinning, LIBBPF_PIN_BY_NAME);
__uint(pinning, BEYLA_PIN_INTERNAL);
} debug_events SEC(".maps");

enum bpf_func_id___x { BPF_FUNC_snprintf___x = 42 /* avoid zero */ };
Expand Down
7 changes: 4 additions & 3 deletions bpf/go_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "trace_util.h"
#include "go_offsets.h"
#include "go_traceparent.h"
#include "pin_internal.h"

char __license[] SEC("license") = "Dual MIT/GPL";

Expand All @@ -47,15 +48,15 @@ struct {
__type(key, go_addr_key_t); // key: pointer to the goroutine
__type(value, goroutine_metadata); // value: timestamp of the goroutine creation
__uint(max_entries, MAX_CONCURRENT_SHARED_REQUESTS);
__uint(pinning, LIBBPF_PIN_BY_NAME);
__uint(pinning, BEYLA_PIN_INTERNAL);
} ongoing_goroutines SEC(".maps");

struct {
__uint(type, BPF_MAP_TYPE_LRU_HASH);
__type(key, go_addr_key_t); // key: pointer to the request goroutine
__type(value, connection_info_t);
__uint(max_entries, MAX_CONCURRENT_SHARED_REQUESTS);
__uint(pinning, LIBBPF_PIN_BY_NAME);
__uint(pinning, BEYLA_PIN_INTERNAL);
} ongoing_server_connections SEC(".maps");

struct {
Expand All @@ -70,7 +71,7 @@ struct {
__type(key, go_addr_key_t); // key: pointer to the goroutine
__type(value, tp_info_t); // value: traceparent info
__uint(max_entries, MAX_CONCURRENT_SHARED_REQUESTS);
__uint(pinning, LIBBPF_PIN_BY_NAME);
__uint(pinning, BEYLA_PIN_INTERNAL);
} go_trace_map SEC(".maps");

static __always_inline void go_addr_key_from_id(go_addr_key_t *current, void *addr) {
Expand Down
11 changes: 6 additions & 5 deletions bpf/http_ssl_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "pid.h"
#include "sockaddr.h"
#include "tcp_info.h"
#include "pin_internal.h"

// We use this map to track ssl handshake enter/exit, it should be only
// temporary
Expand All @@ -17,7 +18,7 @@ struct {
__type(key, u64); // the pid_tid
__type(value, u64); // the SSL struct pointer
__uint(max_entries, MAX_CONCURRENT_SHARED_REQUESTS);
__uint(pinning, LIBBPF_PIN_BY_NAME);
__uint(pinning, BEYLA_PIN_INTERNAL);
} active_ssl_handshakes SEC(".maps");

// LRU map, we don't clean-it up at the moment, which holds onto the mapping
Expand All @@ -28,7 +29,7 @@ struct {
__type(key, u64); // the SSL struct pointer
__type(value, ssl_pid_connection_info_t); // the pointer to the file descriptor matching ssl
__uint(max_entries, MAX_CONCURRENT_SHARED_REQUESTS);
__uint(pinning, LIBBPF_PIN_BY_NAME);
__uint(pinning, BEYLA_PIN_INTERNAL);
} ssl_to_conn SEC(".maps");

// LRU map, we don't clean-it up at the moment, which holds onto the mapping
Expand All @@ -39,7 +40,7 @@ struct {
__type(key, u64); // the pid-tid pair
__type(value, ssl_pid_connection_info_t); // the pointer to the file descriptor matching ssl
__uint(max_entries, MAX_CONCURRENT_SHARED_REQUESTS);
__uint(pinning, LIBBPF_PIN_BY_NAME);
__uint(pinning, BEYLA_PIN_INTERNAL);
} pid_tid_to_conn SEC(".maps");

// LRU map which holds onto the mapping of an ssl pointer to pid-tid,
Expand Down Expand Up @@ -67,15 +68,15 @@ struct {
__uint(max_entries, MAX_CONCURRENT_SHARED_REQUESTS);
__type(key, u64);
__type(value, ssl_args_t);
__uint(pinning, LIBBPF_PIN_BY_NAME);
__uint(pinning, BEYLA_PIN_INTERNAL);
} active_ssl_read_args SEC(".maps");

struct {
__uint(type, BPF_MAP_TYPE_LRU_HASH);
__uint(max_entries, MAX_CONCURRENT_SHARED_REQUESTS);
__type(key, u64);
__type(value, ssl_args_t);
__uint(pinning, LIBBPF_PIN_BY_NAME);
__uint(pinning, BEYLA_PIN_INTERNAL);
} active_ssl_write_args SEC(".maps");

static __always_inline void cleanup_ssl_trace_info(http_info_t *info, void *ssl) {
Expand Down
5 changes: 3 additions & 2 deletions bpf/k_tracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "k_tracer_defs.h"
#include "http_ssl_defs.h"
#include "tc_ip.h"
#include "pin_internal.h"

// Temporary tracking of accept arguments
struct {
Expand Down Expand Up @@ -64,7 +65,7 @@ struct {
partial_connection_info_t); // key: the connection info without the destination address, but with the tcp sequence
__type(value, connection_info_t); // value: traceparent info
__uint(max_entries, 1024);
__uint(pinning, LIBBPF_PIN_BY_NAME);
__uint(pinning, BEYLA_PIN_INTERNAL);
} tcp_connection_map SEC(".maps");

// Used by accept to grab the sock details
Expand Down Expand Up @@ -767,4 +768,4 @@ int app_egress(struct __sk_buff *skb) {
}

return 0;
}
}
9 changes: 5 additions & 4 deletions bpf/nodejs.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,22 @@
#include "pid.h"
#include "ringbuf.h"
#include "map_sizing.h"
#include "pin_internal.h"

struct {
__uint(type, BPF_MAP_TYPE_LRU_HASH);
__type(key, u64); // the pid_tid
__type(value, u64); // the last active async_id
__uint(max_entries, 1000); // 1000 nodejs services, small number, nodejs is single threaded
__uint(pinning, LIBBPF_PIN_BY_NAME);
__uint(pinning, BEYLA_PIN_INTERNAL);
} active_nodejs_ids SEC(".maps");

struct {
__uint(type, BPF_MAP_TYPE_LRU_HASH);
__type(key, u64); // child async_id
__type(value, u64); // parent async_id
__uint(max_entries, MAX_CONCURRENT_REQUESTS);
__uint(pinning, LIBBPF_PIN_BY_NAME);
__uint(pinning, BEYLA_PIN_INTERNAL);
} nodejs_parent_map SEC(".maps");

volatile const s32 async_wrap_async_id_off = 0;
Expand All @@ -32,7 +33,7 @@ struct {
__type(key, u64); // the pid_tid
__type(value, u64); // the last AsyncWrap *
__uint(max_entries, 1000); // 1000 nodejs services, small number, nodejs is single threaded
__uint(pinning, LIBBPF_PIN_BY_NAME);
__uint(pinning, BEYLA_PIN_INTERNAL);
} async_reset_args SEC(".maps");

SEC("uprobe/node:AsyncReset")
Expand Down Expand Up @@ -109,4 +110,4 @@ int emit_async_init(struct pt_regs *ctx) {
return 0;
}

#endif // NODE_JS_H
#endif // NODE_JS_H
7 changes: 4 additions & 3 deletions bpf/pid.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "bpf_core_read.h"
#include "pid_types.h"
#include "bpf_dbg.h"
#include "pin_internal.h"

#define MAX_CONCURRENT_PIDS \
3001 // estimate: 1000 concurrent processes (including children) * 3 namespaces per pid
Expand All @@ -18,15 +19,15 @@ struct {
__uint(max_entries, MAX_CONCURRENT_PIDS);
__type(key, u32);
__type(value, u64); // using 8 bytes, because array elements are 8 bytes aligned anyway
__uint(pinning, LIBBPF_PIN_BY_NAME);
__uint(pinning, BEYLA_PIN_INTERNAL);
} valid_pids SEC(".maps");

struct {
__uint(type, BPF_MAP_TYPE_LRU_HASH);
__uint(max_entries, MAX_CONCURRENT_PIDS);
__type(key, u32);
__type(value, u32);
__uint(pinning, LIBBPF_PIN_BY_NAME);
__uint(pinning, BEYLA_PIN_INTERNAL);
} pid_cache SEC(".maps");

static __always_inline u8 pid_matches(pid_key_t *p) {
Expand Down Expand Up @@ -93,4 +94,4 @@ static __always_inline u32 valid_pid(u64 id) {
return 0;
}

#endif
#endif
6 changes: 6 additions & 0 deletions bpf/pin_internal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef PIN_INTERNAL_H
#define PIN_INTERNAL_H

enum { BEYLA_PIN_INTERNAL = 100 };

#endif
3 changes: 2 additions & 1 deletion bpf/protocol_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "ringbuf.h"
#include "pid.h"
#include "bpf_dbg.h"
#include "pin_internal.h"

#define MIN_HTTP_SIZE 12 // HTTP/1.1 CCC is the smallest valid request we can have
#define RESPONSE_STATUS_POS 9 // HTTP/1.1 <--
Expand Down Expand Up @@ -45,7 +46,7 @@ struct {
__type(key, pid_connection_info_t); // connection that's SSL
__type(value, u64); // ssl
__uint(max_entries, MAX_CONCURRENT_SHARED_REQUESTS);
__uint(pinning, LIBBPF_PIN_BY_NAME);
__uint(pinning, BEYLA_PIN_INTERNAL);
} active_ssl_connections SEC(".maps");

static __always_inline http_connection_metadata_t *empty_connection_meta() {
Expand Down
5 changes: 3 additions & 2 deletions bpf/protocol_http.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "runtime.h"
#include "protocol_common.h"
#include "trace_common.h"
#include "pin_internal.h"

volatile const u32 high_request_volume;

Expand All @@ -27,15 +28,15 @@ struct {
__type(key, pid_connection_info_t);
__type(value, http_info_t);
__uint(max_entries, MAX_CONCURRENT_SHARED_REQUESTS);
__uint(pinning, LIBBPF_PIN_BY_NAME);
__uint(pinning, BEYLA_PIN_INTERNAL);
} ongoing_http SEC(".maps");

struct {
__uint(type, BPF_MAP_TYPE_LRU_HASH);
__type(key, connection_info_t);
__type(value, http_info_t);
__uint(max_entries, 1024);
__uint(pinning, LIBBPF_PIN_BY_NAME);
__uint(pinning, BEYLA_PIN_INTERNAL);
} ongoing_http_fallback SEC(".maps");

// empty_http_info zeroes and return the unique percpu copy in the map
Expand Down
5 changes: 3 additions & 2 deletions bpf/protocol_http2.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "pid.h"
#include "protocol_common.h"
#include "http2_grpc.h"
#include "pin_internal.h"

struct {
__uint(type, BPF_MAP_TYPE_LRU_HASH);
Expand All @@ -21,7 +22,7 @@ struct {
__type(key, http2_conn_stream_t);
__type(value, http2_grpc_request_t);
__uint(max_entries, MAX_CONCURRENT_SHARED_REQUESTS);
__uint(pinning, LIBBPF_PIN_BY_NAME);
__uint(pinning, BEYLA_PIN_INTERNAL);
} ongoing_http2_grpc SEC(".maps");

// We want to be able to collect larger amount of data for the grpc/http headers
Expand Down Expand Up @@ -220,4 +221,4 @@ int protocol_http2(void *ctx) {
return 0;
}

#endif
#endif
3 changes: 2 additions & 1 deletion bpf/protocol_tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@
#include "pid.h"
#include "protocol_common.h"
#include "trace_common.h"
#include "pin_internal.h"

// Keeps track of tcp buffers for unknown protocols
struct {
__uint(type, BPF_MAP_TYPE_LRU_HASH);
__type(key, pid_connection_info_t);
__type(value, tcp_req_t);
__uint(max_entries, MAX_CONCURRENT_SHARED_REQUESTS);
__uint(pinning, LIBBPF_PIN_BY_NAME);
__uint(pinning, BEYLA_PIN_INTERNAL);
} ongoing_tcp_req SEC(".maps");

struct {
Expand Down
3 changes: 2 additions & 1 deletion bpf/ringbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define RINGBUF_H

#include "utils.h"
#include "pin_internal.h"

// These need to line up with some Go identifiers:
// EventTypeHTTP, EventTypeGRPC, EventTypeHTTPClient, EventTypeGRPCClient, EventTypeSQLClient, EventTypeKHTTPRequest
Expand All @@ -28,7 +29,7 @@
struct {
__uint(type, BPF_MAP_TYPE_RINGBUF);
__uint(max_entries, 1 << 16);
__uint(pinning, LIBBPF_PIN_BY_NAME);
__uint(pinning, BEYLA_PIN_INTERNAL);
} events SEC(".maps");

// To be Injected from the user space during the eBPF program load & initialization
Expand Down
5 changes: 3 additions & 2 deletions bpf/trace_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "pid_types.h"
#include "runtime.h"
#include "ringbuf.h"
#include "pin_internal.h"

typedef struct trace_key {
pid_key_t p_key; // pid key as seen by the userspace (for example, inside its container)
Expand All @@ -19,7 +20,7 @@ struct {
__type(key, trace_key_t); // key: pid_tid
__type(value, tp_info_pid_t); // value: traceparent info
__uint(max_entries, MAX_CONCURRENT_SHARED_REQUESTS);
__uint(pinning, LIBBPF_PIN_BY_NAME);
__uint(pinning, BEYLA_PIN_INTERNAL);
} server_traces SEC(".maps");

struct {
Expand All @@ -41,7 +42,7 @@ struct {
__type(key, pid_key_t); // key: the child pid
__type(value, pid_key_t); // value: the parent pid
__uint(max_entries, MAX_CONCURRENT_SHARED_REQUESTS);
__uint(pinning, LIBBPF_PIN_BY_NAME);
__uint(pinning, BEYLA_PIN_INTERNAL);
} clone_map SEC(".maps");

static __always_inline unsigned char *tp_char_buf() {
Expand Down
5 changes: 3 additions & 2 deletions bpf/tracing.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "vmlinux.h"
#include "trace_util.h"
#include "http_types.h"
#include "pin_internal.h"

#define NANOSECONDS_PER_EPOCH (15LL * 1000000000LL) // 15 seconds
#define NANOSECONDS_PER_IMM_EPOCH (100000000LL) // 100 ms
Expand All @@ -12,7 +13,7 @@ struct {
__type(key, connection_info_t); // key: the connection info
__type(value, tp_info_pid_t); // value: traceparent info
__uint(max_entries, MAX_CONCURRENT_SHARED_REQUESTS);
__uint(pinning, LIBBPF_PIN_BY_NAME);
__uint(pinning, BEYLA_PIN_INTERNAL);
} trace_map SEC(".maps");

struct {
Expand Down Expand Up @@ -110,4 +111,4 @@ static __always_inline void new_trace_id(tp_info_t *tp) {
//clear_upper_trace_id(tp);
}

#endif
#endif
Loading

0 comments on commit c9d2647

Please sign in to comment.