bpf: accept any spelling of the addr_space_cast address spaces
Binutils assembler now accepts hex or decimal spellings for address spaces in bpf addr_space_cast instructions, fixing kernel selftests.
This patch series addresses an issue where the Binutils assembler (gas) failed to assemble BPF programs using the ‘addr_space_cast’ instruction when address spaces were specified in hexadecimal. The kernel’s BPF arena selftests were failing because gas was treating hex values as literal characters. The solution introduces a new %DIGIT tag to parse these operands as numbers, allowing for correct comparison and assembly. This change ensures compatibility with GCC’s ‘addr_space_cast()’ support.
- proposer
Proposes to fix gas's handling of BPF addr_space_cast by introducing a %DIGIT tag to parse address spaces as numbers, resolving assembly errors for kernel selftests.
“gas matches the address space characters as literal `0' and `1' and trips over the hex form. Introduce a %DIGIT tag for a constant the opcode already encodes, and parse the operand as a number so the two are compared by value.”
- reviewer
Approves the patch for merging into the master branch, noting that the second version (v2) is accepted.
“Hi Vineet. Thanks for the new version of the patch. OK for master.”
- proposer
Confirms that the patch has been pushed to the master branch.
“Pushed. Thx, -Vineet”
Technical Tradeoffs
- Introducing a new tag (%DIGIT) increases assembler complexity but improves flexibility.
- Ensures compatibility with newer compiler features that use hex for address spaces.
In Details
The bpf subsystem in binutils is being updated to correctly parse hexadecimal representations of address spaces within the addr_space_cast instruction for BPF programs. Previously, the assembler (gas) incorrectly treated hex digits as literal characters, causing assembly failures for certain BPF selftests. This patch modifies tc-bpf.c and related files to introduce a %DIGIT tag, enabling numerical parsing of these operands.
- BPF
- Berkeley Packet Filter, a technology that allows sandboxed programs to make direct use of Linux kernel functions, primarily for networking and security.
- addr_space_cast
- An instruction in some BPF variants used to cast a value between different address spaces.
- gas
- The GNU Assembler, part of the GNU Binutils project, responsible for converting assembly language code into machine code.
- %DIGIT tag
- A new format specifier introduced in this patch to instruct the gas assembler to parse a subsequent operand as a numerical digit, specifically for address space values.