History

bpf: Add BPF_F_ANY_ALIGNMENT.

Often we want to write tests cases that check things like bad context offset accesses. And one way to do this is to use an odd offset on, for example, a 32-bit load. This unfortunately triggers the alignment checks first on platforms that do not set CONFIG_EFFICIENT_UNALIGNED_ACCESS. So the test case see the alignment failure rather than what it was testing for. It is often not completely possible to respect the original intention of the test, or even test the same exact thing, while solving the alignment issue. Another option could have been to check the alignment after the context and other validations are performed by the verifier, but that is a non-trivial change to the verifier.

David Miller committed 7 years ago

Commit e9ee9ef1 parent 88945f48 files · +45 −9Browse files

Showing the changes to tools/include/uapi (1 of 8 files). Show all

Unified · Split

tools/include/uapi/linux/bpf.h+14−0
@@ -232,6 +232,20 @@ enum bpf_attach_type { · 231 unmodified lines
232 */232 */
233#define BPF_F_STRICT_ALIGNMENT (1U << 0)233#define BPF_F_STRICT_ALIGNMENT (1U << 0)
234 234
235/* If BPF_F_ANY_ALIGNMENT is used in BPF_PROF_LOAD command, the
236 * verifier will allow any alignment whatsoever. On platforms
237 * with strict alignment requirements for loads ands stores (such
238 * as sparc and mips) the verifier validates that all loads and
239 * stores provably follow this requirement. This flag turns that
240 * checking and enforcement off.
241 *
242 * It is mostly used for testing when we want to validate the
243 * context and memory access aspects of the verifier, but because
244 * of an unaligned access the alignment check would trigger before
245 * the one we are interested in.
246 */
247#define BPF_F_ANY_ALIGNMENT (1U << 1)
248
235/* when bpf_ldimm64->src_reg == BPF_PSEUDO_MAP_FD, bpf_ldimm64->imm == fd */249/* when bpf_ldimm64->src_reg == BPF_PSEUDO_MAP_FD, bpf_ldimm64->imm == fd */
236#define BPF_PSEUDO_MAP_FD 1250#define BPF_PSEUDO_MAP_FD 1
237 251