Before loading a BPF program, the kernel must verify that the program is safe to run; among other things, that verification includes ensuring that the program will terminate within a bounded time. That requirement has long made writing loops in BPF a challenging task. The situation has improved over the years for some types of loops, but others — including linked-list traversal — are still awkward in BPF programs. A new set of BPF primitives aims to make life easier for this use case through the installation of what can be seen as a sort of circuit breaker.
在加载 BPF 程序之前,内核必须验证该程序是否安全可运行;其中一项验证内容就是确保程序能在有限时间内终止。这个要求长期以来让在 BPF 中编写循环变得极具挑战性。虽然这些年来某些类型的循环情况已有所改善,但其他类型——例如链表遍历——在 BPF 程序中仍然很别扭。为了解决这一问题,一组新的 BPF 原语被提出来,它们的作用类似于安装了一个“断路器”,用以让此类场景更容易实现。

Even relatively simple loops can be hard for the verifier to handle. To the human eye, a loop like this looks safe:
相对便捷的循环,验证器也可能难以处理。对于人类来说,下面这样的循环看起来完全安全:就是即使

for (i = 1; i < 10; i++)
    do_something(i);

It can be hard, though, for the verifier (which is dealing with lower-level code for the BPF virtual machine) to know that nothing will reset the value of the iteration variable in a loop, though; without that assurance, it cannot verify that the loop will terminate as expected. Over the years, a number of helpers have been added to make this kind of iteration easier; they include the bpf_loop() function and generic iterators. This sort of bounded iteration is now relatively easy to do in BPF programs.
然而,对于处理 BPF 虚拟机底层代码的验证器来说,要确定在循环中不会有任何代码重置迭代变量的值是很困难的;没有这种保证,它就无法确认循环一定会按预期终止。多年来,BPF 添加了多个辅助函数来简化这种受限迭代操作;其中包括 bpf_loop() 函数和通用迭代器。如今,这种有界循环在 BPF 程序中已相对容易实现。

If one is iterating through a linked list, though, there is no loop variable that can bound the numbe