A recent Linux kernel change inadvertently broke eBPF programs relying on PT_REGS_RC(regs)
. Intended to optimize register access for x86, this change accidentally cleared the return value register before eBPF programs using kprobe
and kretprobe
could access it. This resulted in eBPF tools like bpftrace
and bcc
showing garbage data instead of expected return values. The issue primarily affects x86 systems running kernel versions 6.5 and later and has already been fixed in 6.5.1, 6.4.12, and 6.1.38. Users of affected kernels should update to receive the fix.
A recent Clang optimization introduced in version 17 regressed performance when compiling code containing large switch statements within inlined functions. This regression manifested as significantly increased compile times, sometimes by orders of magnitude, and occasionally resulted in internal compiler errors. The issue stems from Clang's attempt to optimize switch lowering by transforming it into a series of conditional moves based on jump tables. This optimization, while beneficial in some cases, interacts poorly with inlining, exploding the complexity of the generated intermediate representation (IR) when a function with a large switch is inlined multiple times. This ultimately overwhelms the compiler's later optimization passes. A workaround involves disabling the problematic optimization via a compiler flag (-mllvm -switch-to-lookup-table-threshold=0) until a proper fix is implemented in a future Clang release.
The Hacker News comments discuss a performance regression in Clang involving large switch statements and inlining. Several commenters confirm experiencing similar issues, particularly when compiling large codebases. Some suggest the regression might be related to changes in the inlining heuristics or the way Clang handles jump tables. One commenter points out that using a constexpr
hash table for large switches can be a faster alternative. Another suggests profiling and selective inlining as a workaround. The lack of clear identification of the root cause and the potential impact on compile times and performance are highlighted as concerning. Some users express frustration with the frequency of such regressions in Clang.
Summary of Comments ( 9 )
https://news.ycombinator.com/item?id=43214576
The Hacker News comments discuss the complexities and nuances of the issue presented in the article about
pt_regs
returning garbage in recent Linux kernels due to changes introduced by "Fred." Several commenters express sympathy for Fred, highlighting the challenging trade-offs inherent in kernel development, especially when balancing performance optimizations with backward compatibility. Some point out the difficulties of maintaining eBPF programs across kernel versions and the lack of clear documentation or warnings about these breaking changes. Others delve into the technical specifics, discussing register context, stack unwinding, and the implications for debuggers and profiling tools. The overall sentiment seems to be one of acknowledging the difficulty of the situation and the need for better communication and tooling to navigate such kernel-level changes. A few users also suggest potential workarounds and debugging strategies.The Hacker News post titled "When eBPF pt_regs reads return garbage on the latest Linux kernels, blame Fred" has generated a moderate number of comments, most of which delve into the technical details of the issue and offer further insights or related experiences.
Several commenters discuss the complexities of the
pt_regs
structure and its usage within the eBPF (extended Berkeley Packet Filter) context. One user highlights the inherent fragility of relying on the layout ofpt_regs
, as it is architecture-specific and subject to change. They point out that accessingpt_regs
directly from eBPF programs is essentially working with a "private, unstable ABI" and that a more robust solution would involve explicitly passing the needed register values to the eBPF program. This echoes the sentiment expressed in the original article about the need for a more stable interface for eBPF programs to access register data.Another comment chain focuses on the challenges of maintaining compatibility in the Linux kernel, especially when dealing with low-level structures like
pt_regs
. One commenter mentions the difficulty of keeping track of all the implicit dependencies and the potential for unintended side effects when making changes to core kernel components. They express sympathy for the developers involved, acknowledging the difficulty of balancing performance optimization with maintaining stable ABIs.A couple of commenters share their own experiences with similar issues related to kernel updates and ABI compatibility. One recounts a story of encountering unexpected behavior after a kernel upgrade, which ultimately traced back to changes in internal kernel structures. This anecdote reinforces the point about the inherent risks associated with relying on undocumented or unstable interfaces.
One commenter questions the use of "blame" in the title, suggesting that it is perhaps too strong a word, given that the change was likely unintentional and a consequence of complex system interactions. They advocate for a more understanding approach, acknowledging the difficulty of maintaining such a large and intricate project as the Linux kernel.
The comments also touch upon related topics such as the use of kernel tracing tools, the benefits and drawbacks of eBPF technology, and the trade-offs between performance and stability. While not directly related to the core issue, these comments provide additional context and enrich the discussion.
Overall, the comments on Hacker News provide valuable insights into the complexities of kernel development, the challenges of maintaining ABI compatibility, and the delicate balance between performance and stability. They also offer practical advice for developers working with eBPF and highlight the importance of using stable interfaces whenever possible.