bcc icon indicating copy to clipboard operation
bcc copied to clipboard

libbpf-tools errors:invalid access to map value, value_size=43 off=0 size=0 R1 min value is outside of the allowed memory range

Open Jimskns opened this issue 1 year ago • 0 comments

In my original bpf code, I try to hook the sched_wakeup tracepoint,like this:


SEC("tp_btf/sched_wakeup")
int BPF_PROG(sched_wakeup, struct task_struct *p)
{
	u32 flags = BPF_CORE_READ(p, flags);
	u64 ts = bpf_ktime_get_ns();
	struct piddata* piddatap;
	struct piddata new_piddata = {};
	int ret = 0;
	if (allow_record(flags) && record_launch()) {
		u32 pid = p->pid;
		piddatap = bpf_map_lookup_elem(&start, &pid);
		if (!piddatap) {
			piddatap = &new_piddata;
			piddatap->pid = pid;
			piddatap->blocked_type = 0;
		}
		piddatap->runnable_start_ts = bpf_ktime_get_ns();
		bpf_printk("wakeup pid:%u runnable_start_ts:%llu\n", pid, piddatap->runnable_start_ts);
		ret = bpf_map_update_elem(&start, &pid, piddatap, 0);
	}
	return ret;
}

It works fine. However, when I replace the bpf_printk with bpf_trace_printk

bpf_trace_printk("wakeup pid:%u runnable_start_ts:%llu\n", pid, piddatap->runnable_start_ts);

,I got this error:

; piddatap->runnable_start_ts = bpf_ktime_get_ns();
119: (85) call bpf_ktime_get_ns#5
; piddatap->runnable_start_ts = bpf_ktime_get_ns();
120: (7b) *(u64 *)(r8 +0) = r0
; bpf_trace_printk("wakeup pid:%u runnable_start_ts:%llu\n", pid, piddatap->runnable_start_ts);
121: (61) r2 = *(u32 *)(r10 -124)
122: (18) r1 = 0xffffffc0094fd000
124: (bf) r3 = r0
125: (85) call bpf_trace_printk#6
 R0=inv(id=3) R1_w=map_value(id=0,off=0,ks=4,vs=38,imm=0) R2_w=inv(id=0,umax_value=4294967295,var_off=(0x0; 0xffffffff)) R3_w=inv(id=3) R6=inv(id=1) R7=fp-120 R8=fp-80 R9=ptr_task_struct(id=0,off=0,imm=0) R10=fp0 fp-8=0000mmmm fp-16=mmmmmmmm fp-24=mmmm0000 fp-32=00000000 fp-40=00000000 fp-48=00000000 fp-56=00000000 fp-64=00000000 fp-72=00000000 fp-80_w=mmmmmmmm fp-88=00000000 fp-96=00000000 fp-104=inv2 fp-112=00000000 fp-120=0000mmmm fp-128=mmmm????
invalid access to map value, value_size=38 off=0 size=0
R1 min value is outside of the allowed memory range
processed 84 insns (limit 1000000) max_states_per_insn 0 total_states 6 peak_states 6 mark_read 3
-- END PROG LOAD LOG --

Could you help me please?

Jimskns avatar Oct 26 '23 07:10 Jimskns