Cannot access kernel percpu variables, LLVM error parsing inline asm because %gs is invalid register/token name
- Dominant language
- C
- Stars
- 22.7k
- Forks
- 4.1k
- Avg merge
- 10d 4h
- Merged PRs (30d)
- 3
Description
I am trying to read preempt_count in a bcc program, but can't get it done, because preempt_count() ends up reading kernel percpu variables in asm code which accesses %gs register, but LLVM doesn't recognize it and reports invalid register error as follows:
`:1:2: error: invalid register/token name
movl %gs:(r1 + 0),r1
^
LLVM ERROR: Error parsing inline asm
`
Not only preempt_count, any kernel percpu variables I don't know how to read via bcc programs. Appreciate very much if someone would kindly help.
The code looks like:
> prg = """
...
int perf_cpu_clock(struct bpf_perf_event_data *ctx) {
...
data.preempt_count = preempt_count();
...
}
"""
b = BPF(text=prog)
b.attach_perf_event(ev_type=PerfType.SOFTWARE, ev_config=PerfSWConfig.CPU_CLOCK, fn_name="perf_cpu_clock", sample_period=0, sample_freq=99, cpu=-1)
b["events"].open_perf_buffer(process_event)
...
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the BPF(text=prog) example with perf_cpu_clock and preempt_count(), then trace how BCC passes the inline assembly to LLVM. Done means kernel percpu variables such as preempt_count can be accessed without LLVM rejecting the %gs register or reporting an invalid register/token name.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c, linux, python
- Domain
- operating-systems, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100