Daniel Borkmann says: ==================== pull-request: bpf-next 2022-09-05 The following pull-request contains BPF updates for your *net-next* tree. We've added 106 non-merge commits during the last 18 day(s) which contain a total of 159 files changed, 5225 insertions(+), 1358 deletions(-). There are two small merge conflicts, resolve them as follows: 1) tools/testing/selftests/bpf/DENYLIST.s390x Commit 27e23836ce22 ("selftests/bpf: Add lru_bug to s390x deny list") in bpf tree was needed to get BPF CI green on s390x, but it conflicted with newly added tests on bpf-next. Resolve by adding both hunks, result: [...] lru_bug # prog 'printk': failed to auto-attach: -524 setget_sockopt # attach unexpected error: -524 (trampoline) cb_refs # expected error message unexpected error: -524 (trampoline) cgroup_hierarchical_stats # JIT does not support calling kernel function (kfunc) htab_update # failed to attach: ERROR: strerror_r(-524)=22 (trampoline) [...] 2) net/core/filter.c Commit 1227c1771dd2 ("net: Fix data-races around sysctl_[rw]mem_(max|default).") from net tree conflicts with commit 29003875bd5b ("bpf: Change bpf_setsockopt(SOL_SOCKET) to reuse sk_setsockopt()") from bpf-next tree. Take the code as it is from bpf-next tree, result: [...] if (getopt) { if (optname == SO_BINDTODEVICE) return -EINVAL; return sk_getsockopt(sk, SOL_SOCKET, optname, KERNEL_SOCKPTR(optval), KERNEL_SOCKPTR(optlen)); } return sk_setsockopt(sk, SOL_SOCKET, optname, KERNEL_SOCKPTR(optval), *optlen); [...] The main changes are: 1) Add any-context BPF specific memory allocator which is useful in particular for BPF tracing with bonus of performance equal to full prealloc, from Alexei Starovoitov. 2) Big batch to remove duplicated code from bpf_{get,set}sockopt() helpers as an effort to reuse the existing core socket code as much as possible, from Martin KaFai Lau. 3) Extend BPF flow dissector for BPF programs to just augment the in-kernel dissector with custom logic. In other words, allow for partial replacement, from Shmulik Ladkani. 4) Add a new cgroup iterator to BPF with different traversal options, from Hao Luo. 5) Support for BPF to collect hierarchical cgroup statistics efficiently through BPF integration with the rstat framework, from Yosry Ahmed. 6) Support bpf_{g,s}et_retval() under more BPF cgroup hooks, from Stanislav Fomichev. 7) BPF hash table and local storages fixes under fully preemptible kernel, from Hou Tao. 8) Add various improvements to BPF selftests and libbpf for compilation with gcc BPF backend, from James Hilliard. 9) Fix verifier helper permissions and reference state management for synchronous callbacks, from Kumar Kartikeya Dwivedi. 10) Add support for BPF selftest's xskxceiver to also be used against real devices that support MAC loopback, from Maciej Fijalkowski. 11) Various fixes to the bpf-helpers(7) man page generation script, from Quentin Monnet. 12) Document BPF verifier's tnum_in(tnum_range(), ...) gotchas, from Shung-Hsi Yu. 13) Various minor misc improvements all over the place. * https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next: (106 commits) bpf: Optimize rcu_barrier usage between hash map and bpf_mem_alloc. bpf: Remove usage of kmem_cache from bpf_mem_cache. bpf: Remove prealloc-only restriction for sleepable bpf programs. bpf: Prepare bpf_mem_alloc to be used by sleepable bpf programs. bpf: Remove tracing program restriction on map types bpf: Convert percpu hash map to per-cpu bpf_mem_alloc. bpf: Add percpu allocation support to bpf_mem_alloc. bpf: Batch call_rcu callbacks instead of SLAB_TYPESAFE_BY_RCU. bpf: Adjust low/high watermarks in bpf_mem_cache bpf: Optimize call_rcu in non-preallocated hash map. bpf: Optimize element count in non-preallocated hash map. bpf: Relax the requirement to use preallocated hash maps in tracing progs. samples/bpf: Reduce syscall overhead in map_perf_test. selftests/bpf: Improve test coverage of test_maps bpf: Convert hash map to bpf_mem_alloc. bpf: Introduce any context BPF specific memory allocator. selftest/bpf: Add test for bpf_getsockopt() bpf: Change bpf_getsockopt(SOL_IPV6) to reuse do_ipv6_getsockopt() bpf: Change bpf_getsockopt(SOL_IP) to reuse do_ip_getsockopt() bpf: Change bpf_getsockopt(SOL_TCP) to reuse do_tcp_getsockopt() ... ====================
Showing the changes to scripts (1 of 159 files). Show all
Unified · Split
| @@ -10,6 +10,9 @@ from __future__ import print_function · 9 unmodified lines | |||
| 10 | import argparse | 10 | import argparse |
| 11 | import re | 11 | import re |
| 12 | import sys, os | 12 | import sys, os |
| 13 | import subprocess | ||
| 14 | |||
| 15 | helpersDocStart = 'Start of BPF helper function descriptions:' | ||
| 13 | 16 | ||
| 14 | class NoHelperFound(BaseException): | 17 | class NoHelperFound(BaseException): |
| 15 | pass | 18 | pass |
| @@ -47,6 +50,10 @@ class Helper(APIElement): · 31 unmodified lines | |||
| 47 | @desc: textual description of the helper function | 50 | @desc: textual description of the helper function |
| 48 | @ret: description of the return value of the helper function | 51 | @ret: description of the return value of the helper function |
| 49 | """ | 52 | """ |
| 53 | def __init__(self, *args, **kwargs): | ||
| 54 | super().__init__(*args, **kwargs) | ||
| 55 | self.enum_val = None | ||
| 56 | |||
| 50 | def proto_break_down(self): | 57 | def proto_break_down(self): |
| 51 | """ | 58 | """ |
| 52 | Break down helper function protocol into smaller chunks: return type, | 59 | Break down helper function protocol into smaller chunks: return type, |
| @@ -89,6 +96,7 @@ class HeaderParser(object): · 36 unmodified lines | |||
| 89 | self.commands = [] | 96 | self.commands = [] |
| 90 | self.desc_unique_helpers = set() | 97 | self.desc_unique_helpers = set() |
| 91 | self.define_unique_helpers = [] | 98 | self.define_unique_helpers = [] |
| 99 | self.helper_enum_vals = {} | ||
| 92 | self.desc_syscalls = [] | 100 | self.desc_syscalls = [] |
| 93 | self.enum_syscalls = [] | 101 | self.enum_syscalls = [] |
| 94 | 102 | ||
| @@ -233,7 +241,7 @@ class HeaderParser(object): · 138 unmodified lines | |||
| 233 | self.enum_syscalls = re.findall('(BPF\w+)+', bpf_cmd_str) | 241 | self.enum_syscalls = re.findall('(BPF\w+)+', bpf_cmd_str) |
| 234 | 242 | ||
| 235 | def parse_desc_helpers(self): | 243 | def parse_desc_helpers(self): |
| 236 | self.seek_to('* Start of BPF helper function descriptions:', | 244 | self.seek_to(helpersDocStart, |
| 237 | 'Could not find start of eBPF helper descriptions list') | 245 | 'Could not find start of eBPF helper descriptions list') |
| 238 | while True: | 246 | while True: |
| 239 | try: | 247 | try: |
| @@ -245,30 +253,54 @@ class HeaderParser(object): · 5 unmodified lines | |||
| 245 | break | 253 | break |
| 246 | 254 | ||
| 247 | def parse_define_helpers(self): | 255 | def parse_define_helpers(self): |
| 248 | # Parse the number of FN(...) in #define __BPF_FUNC_MAPPER to compare | 256 | # Parse FN(...) in #define __BPF_FUNC_MAPPER to compare later with the |
| 249 | # later with the number of unique function names present in description. | 257 | # number of unique function names present in description and use the |
| 258 | # correct enumeration value. | ||
| 250 | # Note: seek_to(..) discards the first line below the target search text, | 259 | # Note: seek_to(..) discards the first line below the target search text, |
| 251 | # resulting in FN(unspec) being skipped and not added to self.define_unique_helpers. | 260 | # resulting in FN(unspec) being skipped and not added to self.define_unique_helpers. |
| 252 | self.seek_to('#define __BPF_FUNC_MAPPER(FN)', | 261 | self.seek_to('#define __BPF_FUNC_MAPPER(FN)', |
| 253 | 'Could not find start of eBPF helper definition list') | 262 | 'Could not find start of eBPF helper definition list') |
| 254 | # Searches for either one or more FN(\w+) defines or a backslash for newline | 263 | # Searches for one FN(\w+) define or a backslash for newline |
| 255 | p = re.compile('\s*(FN\(\w+\))+|\\\\') | 264 | p = re.compile('\s*FN\((\w+)\)|\\\\') |
| 256 | fn_defines_str = '' | 265 | fn_defines_str = '' |
| 266 | i = 1 # 'unspec' is skipped as mentioned above | ||
| 257 | while True: | 267 | while True: |
| 258 | capture = p.match(self.line) | 268 | capture = p.match(self.line) |
| 259 | if capture: | 269 | if capture: |
| 260 | fn_defines_str += self.line | 270 | fn_defines_str += self.line |
| 271 | self.helper_enum_vals[capture.expand(r'bpf_\1')] = i | ||
| 272 | i += 1 | ||
| 261 | else: | 273 | else: |
| 262 | break | 274 | break |
| 263 | self.line = self.reader.readline() | 275 | self.line = self.reader.readline() |
| 264 | # Find the number of occurences of FN(\w+) | 276 | # Find the number of occurences of FN(\w+) |
| 265 | self.define_unique_helpers = re.findall('FN\(\w+\)', fn_defines_str) | 277 | self.define_unique_helpers = re.findall('FN\(\w+\)', fn_defines_str) |
| 266 | 278 | ||
| 279 | def assign_helper_values(self): | ||
| 280 | seen_helpers = set() | ||
| 281 | for helper in self.helpers: | ||
| 282 | proto = helper.proto_break_down() | ||
| 283 | name = proto['name'] | ||
| 284 | try: | ||
| 285 | enum_val = self.helper_enum_vals[name] | ||
| 286 | except KeyError: | ||
| 287 | raise Exception("Helper %s is missing from enum bpf_func_id" % name) | ||
| 288 | |||
| 289 | # Enforce current practice of having the descriptions ordered | ||
| 290 | # by enum value. | ||
| 291 | seen_helpers.add(name) | ||
| 292 | desc_val = len(seen_helpers) | ||
| 293 | if desc_val != enum_val: | ||
| 294 | raise Exception("Helper %s comment order (#%d) must be aligned with its position (#%d) in enum bpf_func_id" % (name, desc_val, enum_val)) | ||
| 295 | |||
| 296 | helper.enum_val = enum_val | ||
| 297 | |||
| 267 | def run(self): | 298 | def run(self): |
| 268 | self.parse_desc_syscall() | 299 | self.parse_desc_syscall() |
| 269 | self.parse_enum_syscall() | 300 | self.parse_enum_syscall() |
| 270 | self.parse_desc_helpers() | 301 | self.parse_desc_helpers() |
| 271 | self.parse_define_helpers() | 302 | self.parse_define_helpers() |
| 303 | self.assign_helper_values() | ||
| 272 | self.reader.close() | 304 | self.reader.close() |
| 273 | 305 | ||
| 274 | ############################################################################### | 306 | ############################################################################### |
| @@ -357,6 +389,31 @@ class PrinterRST(Printer): · 82 unmodified lines | |||
| 357 | 389 | ||
| 358 | print('') | 390 | print('') |
| 359 | 391 | ||
| 392 | def get_kernel_version(self): | ||
| 393 | try: | ||
| 394 | version = subprocess.run(['git', 'describe'], cwd=linuxRoot, | ||
| 395 | capture_output=True, check=True) | ||
| 396 | version = version.stdout.decode().rstrip() | ||
| 397 | except: | ||
| 398 | try: | ||
| 399 | version = subprocess.run(['make', 'kernelversion'], cwd=linuxRoot, | ||
| 400 | capture_output=True, check=True) | ||
| 401 | version = version.stdout.decode().rstrip() | ||
| 402 | except: | ||
| 403 | return 'Linux' | ||
| 404 | return 'Linux {version}'.format(version=version) | ||
| 405 | |||
| 406 | def get_last_doc_update(self, delimiter): | ||
| 407 | try: | ||
| 408 | cmd = ['git', 'log', '-1', '--pretty=format:%cs', '--no-patch', | ||
| 409 | '-L', | ||
| 410 | '/{}/,/\*\//:include/uapi/linux/bpf.h'.format(delimiter)] | ||
| 411 | date = subprocess.run(cmd, cwd=linuxRoot, | ||
| 412 | capture_output=True, check=True) | ||
| 413 | return date.stdout.decode().rstrip() | ||
| 414 | except: | ||
| 415 | return '' | ||
| 416 | |||
| 360 | class PrinterHelpersRST(PrinterRST): | 417 | class PrinterHelpersRST(PrinterRST): |
| 361 | """ | 418 | """ |
| 362 | A printer for dumping collected information about helpers as a ReStructured | 419 | A printer for dumping collected information about helpers as a ReStructured |
| @@ -378,6 +435,8 @@ list of eBPF helper functions · 15 unmodified lines | |||
| 378 | ------------------------------------------------------------------------------- | 435 | ------------------------------------------------------------------------------- |
| 379 | 436 | ||
| 380 | :Manual section: 7 | 437 | :Manual section: 7 |
| 438 | :Version: {version} | ||
| 439 | {date_field}{date} | ||
| 381 | 440 | ||
| 382 | DESCRIPTION | 441 | DESCRIPTION |
| 383 | =========== | 442 | =========== |
| @@ -410,8 +469,13 @@ kernel at the top). · 26 unmodified lines | |||
| 410 | HELPERS | 469 | HELPERS |
| 411 | ======= | 470 | ======= |
| 412 | ''' | 471 | ''' |
| 472 | kernelVersion = self.get_kernel_version() | ||
| 473 | lastUpdate = self.get_last_doc_update(helpersDocStart) | ||
| 474 | |||
| 413 | PrinterRST.print_license(self) | 475 | PrinterRST.print_license(self) |
| 414 | print(header) | 476 | print(header.format(version=kernelVersion, |
| 477 | date_field = ':Date: ' if lastUpdate else '', | ||
| 478 | date=lastUpdate)) | ||
| 415 | 479 | ||
| 416 | def print_footer(self): | 480 | def print_footer(self): |
| 417 | footer = ''' | 481 | footer = ''' |
| @@ -761,7 +825,7 @@ class PrinterHelpers(Printer): · 343 unmodified lines | |||
| 761 | comma = ', ' | 825 | comma = ', ' |
| 762 | print(one_arg, end='') | 826 | print(one_arg, end='') |
| 763 | 827 | ||
| 764 | print(') = (void *) %d;' % len(self.seen_helpers)) | 828 | print(') = (void *) %d;' % helper.enum_val) |
| 765 | print('') | 829 | print('') |
| 766 | 830 | ||
| 767 | ############################################################################### | 831 | ############################################################################### |