title: BPF verifier rejecting XDP program due to back-edge even though pragma unroll is used
body: <p>So, as per title I'm trying to load an XDP program, when surprisingly the bpf verifier kicks in spitting in my face with the famous <strong><em>back-edge</em></strong> error:</p>
  <pre><code>libbpf: load bpf program failed: Invalid argument
  libbpf: -- BEGIN DUMP LOG ---
  libbpf: 
  back-edge from insn 271 to 69
  
  libbpf: -- END LOG --
  libbpf: failed to load program 'xdp_prog'
  </code></pre>
  <p>Even though the only for-loop - with the number of iterations known at compile time - in my restricted ebpf C code is guarded by <code>pragma unroll</code>. Here's a code snippet showing the affected for-loop as defined inside an <code>__always_inline</code>d function:</p>
  <pre><code>#pragma unroll
  for (i = 0; i &lt; 8; i++)
  {
      int k = idx + i;
      mask = bpf_map_lookup_elem(&amp;a_map, &amp;k);
      if (!mask || (mask-&gt;an_idx == 0))
          return -1;
  
      *m_key = *key;
      foo(m_key, mask);  // an __alwais_inline func
  
      id = bpf_map_lookup_elem(&amp;b_map, m_key);
      if (id)
      {
          *out_id = *id;
          return 0;
      }
  }
  </code></pre>
  <p>Maybe the problem is with clang failing to unroll the loop? If that's right, why does it fail, is there any workaround? It's unacceptable to manually unroll the loop as it results in a horrendous, unmaintainable, and unreadable code.</p>
  <p>Oh, I'm working with:</p>
  <ul>
  <li>kernel 4.19.3</li>
  <li>llvm-clang 8</li>
  </ul>
  <p>Any thoughts?</p>
  <p><strong>UPDATE</strong><br />
  Just noticed that even the following dummy for-loop seems not to be unrolled, with the bpf verifier complaining about back-edge:</p>
  <pre><code>#pragma unroll
  for (i = 0; i &lt; 8; i++)
  {
      int k = i;
      mask = bpf_map_lookup_elem(&amp;a_map, &amp;k);
  }
  </code></pre>
  <p>Is it just me for this doesn't make any sense?</p>