Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xdp: add breadcrumbs for logging #589

Merged
merged 1 commit into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/app/fdctl/Local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ ifdef FD_HAS_DOUBLE
$(call make-lib,fd_fdctl)
$(call add-objs,main config security utility run keygen monitor/monitor monitor/helper configure/configure configure/large_pages configure/sysctl configure/shmem configure/xdp configure/xdp_leftover configure/ethtool configure/workspace_leftover configure/workspace,fd_fdctl)
$(call make-bin,fdctl,main1,fd_fdctl fd_frank fd_disco fd_ballet fd_tango fd_util fd_quic solana_validator_fd)
$(OBJDIR)/bin/fdctl: src/app/fdctl/config/default.toml
$(OBJDIR)/obj/app/fdctl/configure/xdp.o: src/tango/xdp/fd_xdp_redirect_prog.o
$(OBJDIR)/obj/app/fdctl/config.o: src/app/fdctl/config/default.toml
endif
endif
endif
Expand Down
1 change: 1 addition & 0 deletions src/tango/xdp/fd_xdp_license.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#define FD_LICENSE "Apache-2.0"
29 changes: 28 additions & 1 deletion src/tango/xdp/fd_xdp_redirect_prog.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include "../ebpf/fd_ebpf_base.h"
#include "fd_xdp_redirect_prog.h"
#include "fd_xdp_license.h"

#include <linux/bpf.h>

Expand All @@ -30,9 +31,10 @@

/* Metadata ***********************************************************/

char __license[] __attribute__(( section("license") )) = "Apache-2.0";
char __license[] __attribute__(( section("license") )) = FD_LICENSE;

/* eBPF syscalls ******************************************************/
/* https://github.com/torvalds/linux/blob/91aa6c412d7f85e48aead7b00a7d9e91f5cf5863/include/uapi/linux/bpf.h#L5577 */

static void *
(* bpf_map_lookup_elem)( void * map,
Expand All @@ -45,6 +47,31 @@ static long
ulong flags )
= (void *)51U;

#ifdef FD_XDP_LOGGING

/* To do logging, you should enable this import and then call it like

char fmt[] = "hello %d";
bpf_trace_printk( fmt, sizeof(fmt), 5 );

Note that BPF logging only supports certain format specifiers and
can take at most three arguments. It is extremely fickle and the
program may just start randomly failing to load with a verifier
error. Move things around and try again.

Firedancer is not using a GPL compatible license, and BPF printk
is a GPL part of BPF. This means that we cannot use it, or ship
this code in the binary. The kernel checks this with the "license"
section exported above, which you should not change.
*/
static long
(*bpf_trace_printk)( const char * fmt,
uint fmt_size,
... )
= (void *) 6;

#endif

/* eBPF maps **********************************************************/

/* eBPF maps allows sharing information between the Linux userspace and
Expand Down
7 changes: 3 additions & 4 deletions src/tango/xdp/fd_xdp_redirect_user.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#define _DEFAULT_SOURCE
#include "fd_xdp_redirect_user.h"
#include "fd_xdp_redirect_prog.h"
#include "fd_xdp_license.h"
#include "../../ballet/ebpf/fd_ebpf.h"
#include "../../util/fd_util.h"

Expand Down Expand Up @@ -328,7 +329,7 @@ fd_xdp_hook_iface( char const * app_name,
.prog_type = BPF_PROG_TYPE_XDP,
.insn_cnt = (uint) ( res->bpf_sz / 8UL ),
.insns = (ulong)( res->bpf ),
.license = (ulong)"Apache-2.0",
.license = (ulong)FD_LICENSE,
/* Verifier logs */
.log_level = 6,
.log_size = EBPF_KERN_LOG_BUFSZ,
Expand All @@ -338,9 +339,7 @@ fd_xdp_hook_iface( char const * app_name,
if( FD_UNLIKELY( prog_fd<0 ) ) {
FD_LOG_WARNING(( "bpf(BPF_PROG_LOAD, insns=%p, insn_cnt=%lu) failed (%d-%s)",
(void *)res->bpf, res->bpf_sz / 8UL, errno, strerror( errno ) ));
if( errno==EACCES ) {
FD_LOG_NOTICE(( "eBPF verifier log:\n%s", ebpf_kern_log ));
}
FD_LOG_NOTICE(( "eBPF verifier log:\n%s", ebpf_kern_log ));
return -1;
}

Expand Down
Loading