This is an archive of the discontinued LLVM Phabricator instance.

[BPF] fix a CO-RE issue with -mattr=+alu32
ClosedPublic

Authored by yonghong-song on Oct 25 2019, 10:56 AM.

Details

Summary

Ilya Leoshkevich (<iii@linux.ibm.com>) reported an issue that
with -mattr=+alu32 CO-RE has a segfault in BPF MISimplifyPatchable
pass.

The pattern will be transformed by MISimplifyPatchable
pass looks like below:

r5 = ld_imm64 @"b:0:0$0:0"
r2 = ldw r5, 0
... r2 ... // use r2

The pass will remove the intermediate 'ldw' instruction
and replacing all r2 with r5 likes below:

r5 = ld_imm64 @"b:0:0$0:0"
... r5 ... // use r5

Later, the ld_imm64 insn will be replaced with

r5 = <patched immediate>

for field relocation purpose.

With -mattr=+alu32, the input code may become

r5 = ld_imm64 @"b:0:0$0:0"
w2 = ldw32 r5, 0
... w2 ... // use w2

Replacing "w2" with "r5" is incorrect and will
trigger compiler internal errors.

To fix the problem, if the register class of ldw* dest
register is sub_32, we just replace the original ldw*
register with:

w2 = w5

Directly replacing all uses of w2 with in-place
constructed w5 for the use operand seems not working in all cases.

The latest kernel will have -mattr=+alu32 on by default,
so added this flag to all CORE tests.
Tested with latest kernel bpf-next branch as well with this patch.

Diff Detail

Event Timeline

yonghong-song created this revision.Oct 25 2019, 10:56 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 25 2019, 10:56 AM
ast accepted this revision.Oct 25 2019, 11:11 AM
This revision is now accepted and ready to land.Oct 25 2019, 11:11 AM
This revision was automatically updated to reflect the committed changes.