https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117068

            Bug ID: 117068
           Summary: bpf: add support for preserve_static_offset attribute
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: cupertino.miranda at oracle dot com
  Target Milestone: ---

BPF verifier imposes special code limitations when accessing specific
variables/arguments.

One example is for the access to "context pointers" struct fields (provided in
R1 at application start).
Any load or store to a context pointer must always be in the form of
"register+offset" to which the register would contain the address to the base
of the structure and the full offset for the field being accessed.
Any early offset computation to a context pointer register/value does (for the
verifier) declassify the register from being a context pointer and denies any
loads or stores from using the mutated register.

An actual example of such denying is this selftest run fail:

reg type unsupported for arg#0 function get_vma_offset#8723
0: R1=ctx() R10=fp0
0: (18) r0 = 0x10                     ; R0_w=16
2: (bf) r2 = r1                       ; R1=ctx() R2_w=ctx()
3: (0f) r2 += r0                      ; R0_w=16 R2_w=ctx(off=16)
4: (79) r0 = *(u64 *)(r1 +8)        ;R0_w=ptr_or_null_task_struct(id=1)
R1=ctx();
5: (15) if r0 == 0x0 goto pc+21       ; R0_w=ptr_task_struct()
6: (79) r2 = *(u64 *)(r2 +0)
dereference of modified ctx ptr R2 off=16 disallowed

BPF verifier documentation describing the limitations:
  https://docs.kernel.org/bpf/verifier.html

Compilers do not by default have the constructs to impose these target
limitations.
LLVM solution for this problem is to define the struct attribute
preserve_static_offset that will enforce that any reference to the particular
struct would respect the BPF verifier requirements.

LLVM proposal at:
  https://reviews.llvm.org/D133361

Reply via email to