OSDN Git Service

samples/bpf: fix symbol mismatch by compiler optimization
authorDaniel T. Lee <danieltimlee@gmail.com>
Fri, 18 Aug 2023 09:01:14 +0000 (18:01 +0900)
committerAlexei Starovoitov <ast@kernel.org>
Mon, 21 Aug 2023 22:39:09 +0000 (15:39 -0700)
Currently, multiple kprobe programs are suffering from symbol mismatch
due to compiler optimization. These optimizations might induce
additional suffix to the symbol name such as '.isra' or '.constprop'.

    # egrep ' finish_task_switch| __netif_receive_skb_core' /proc/kallsyms
    ffffffff81135e50 t finish_task_switch.isra.0
    ffffffff81dd36d0 t __netif_receive_skb_core.constprop.0
    ffffffff8205cc0e t finish_task_switch.isra.0.cold
    ffffffff820b1aba t __netif_receive_skb_core.constprop.0.cold

To avoid this, this commit replaces the original kprobe section to
kprobe.multi in order to match symbol with wildcard characters. Here,
asterisk is used for avoiding symbol mismatch.

Signed-off-by: Daniel T. Lee <danieltimlee@gmail.com>
Link: https://lore.kernel.org/r/20230818090119.477441-5-danieltimlee@gmail.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
samples/bpf/offwaketime.bpf.c
samples/bpf/tracex1.bpf.c

index 8e51058..3200a0f 100644 (file)
@@ -118,7 +118,7 @@ int oncpu(struct trace_event_raw_sched_switch *ctx)
        /* record previous thread sleep time */
        u32 pid = ctx->prev_pid;
 #else
-SEC("kprobe/finish_task_switch")
+SEC("kprobe.multi/finish_task_switch*")
 int oncpu(struct pt_regs *ctx)
 {
        struct task_struct *p = (void *) PT_REGS_PARM1(ctx);
index bb78bdb..f3be14a 100644 (file)
  * Number of arguments and their positions can change, etc.
  * In such case this bpf+kprobe example will no longer be meaningful
  */
-SEC("kprobe/__netif_receive_skb_core")
+SEC("kprobe.multi/__netif_receive_skb_core*")
 int bpf_prog1(struct pt_regs *ctx)
 {
        /* attaches to kprobe __netif_receive_skb_core,
         * looks for packets on loobpack device and prints them
+        * (wildcard is used for avoiding symbol mismatch due to optimization)
         */
        char devname[IFNAMSIZ];
        struct net_device *dev;