[PATCH bpf-next] Support load time binding of bpf-helpers.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



BPF helper function names are common across different platforms, but the
id assigned to helper functions may vary. This change provides an option
to generate eBPF ELF files with relocations for helper functions which
permits resolving helper function names to ids at load time instead of
at compile time.

Add a level of indirection to bpf_doc.py (and generated bpf_helper_defs.h)
to permit compile time generation of bpf-helper function declarations to
facilitating late binding of bpf-helpers to helper id for cases where
different platforms use different helper ids, but the same helper
functions.

Example use case would be:
"#define BPF_HELPER(return_type, name, args, id) \
    extern return_type name args"

To generate:
extern void * bpf_map_lookup_elem (void *map, const void *key);

Instead of:
static void *(*bpf_map_lookup_elem) (void *map, const void *key) \
    = (void*) 1;

This would result in the bpf-helpers having external linkage and permit
late binding of BPF programs to helper function ids.

Signed-off-by: Alan Jowett <alanjo@xxxxxxxxxxxxx>
---
 scripts/bpf_helpers_doc.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/scripts/bpf_helpers_doc.py b/scripts/bpf_helpers_doc.py
index 867ada23281c..442b5e87687e 100755
--- a/scripts/bpf_helpers_doc.py
+++ b/scripts/bpf_helpers_doc.py
@@ -519,6 +519,10 @@ class PrinterHelpers(Printer):
         for fwd in self.type_fwds:
             print('%s;' % fwd)
         print('')
+        print('#ifndef BPF_HELPER')
+        print('#define BPF_HELPER(return_type, name, args, id) static return_type(*name) args = (void*) id')
+        print('#endif')
+        print('')
 
     def print_footer(self):
         footer = ''
@@ -558,7 +562,7 @@ class PrinterHelpers(Printer):
                 print(' *{}{}'.format(' \t' if line else '', line))
 
         print(' */')
-        print('static %s %s(*%s)(' % (self.map_type(proto['ret_type']),
+        print('BPF_HELPER(%s%s, %s, (' % (self.map_type(proto['ret_type']),
                                       proto['ret_star'], proto['name']), end='')
         comma = ''
         for i, a in enumerate(proto['args']):
@@ -577,7 +581,7 @@ class PrinterHelpers(Printer):
             comma = ', '
             print(one_arg, end='')
 
-        print(') = (void *) %d;' % len(self.seen_helpers))
+        print('), %d);' % len(self.seen_helpers))
         print('')
 
 ###############################################################################
-- 
2.25.1




[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux