Re: Why does bpf_probe_read also release relocation information?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 





On 5/24/21 10:34 AM, Yonghong Song wrote:


On 5/23/21 7:24 PM, Shuyi Cheng wrote:
Hello everyone,

I would like to ask a question. The question is: Why does bpf_probe_read not use __builtin_preserve_access_index and also release relocation information?

The following document is from: https://github.com/libbpf/libbpf/blob/57375504c6c9766d23f178c40f71bf5e8df9363d/src/libbpf_internal.h#L414

  * Such relocation is emitted when using __builtin_preserve_access_index()
  * Clang built-in, passing expression that captures field address, e.g.:
  *
  * bpf_probe_read(&dst, sizeof(dst),
  *          __builtin_preserve_access_index(&src->a.b.c));
  *
  * In this case Clang will emit field relocation recording necessary data to
  * be able to find offset of embedded `a.b.c` field within `src` struct.


This document clearly explains the function of __builtin_preserve_access_index. However, I did a small test. The test results show that only using bpf_probe_read and not using __builtin_preserve_access_index will also be relocated.The specific test content is as follows:

// The bpf program.
SEC("kprobe/kfree_skb")
int BPF_PROG(kprobe__kfree_skb,struct sk_buff *skb)
{
     unsigned char *data;
     bpf_probe_read(&data,sizeof(data),&skb->data);
     return 0;
}

// The debug log.
libbpf: CO-RE relocating [0] struct sk_buff: found target candidate [3057] struct sk_buff in [vmlinux] libbpf: CO-RE relocating [0] struct sk_buff: found target candidate [23925] struct sk_buff in [vmlinux] libbpf: prog 'kprobe__kfree_skb': relo #0: matching candidate #0 [3057] struct sk_buff.data (0:77 @ offset 240) libbpf: prog 'kprobe__kfree_skb': relo #0: matching candidate #1 [23925] struct sk_buff.data (0:77 @ offset 240) libbpf: prog 'kprobe__kfree_skb': relo #0: patched insn #0 (ALU/ALU64) imm 240 -> 240

Did you include "vmlinux.h" in your program? The "vmlinux.h" contains

#ifndef BPF_NO_PRESERVE_ACCESS_INDEX
#pragma clang attribute push (__attribute__((preserve_access_index)), apply_to = record)
#endif

which will put preserve_access_index to all record (struct/union) definitions. So the above "sk_buff" member access will be relocated
automatically by libbpf.


Yes, i inclue "vmlinux.h". I understand, Thank you very much for answering my doubts.:-)


Thanks in advance for your help,
Cheng





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux