BPF List
 help / color / mirror / Atom feed
* Idea for "function meta"
@ 2024-12-20 13:57 Menglong Dong
  2024-12-20 14:00 ` Peter Zijlstra
  0 siblings, 1 reply; 7+ messages in thread
From: Menglong Dong @ 2024-12-20 13:57 UTC (permalink / raw)
  To: Alexei Starovoitov, Peter Zijlstra; +Cc: bpf

Hello, all.

In the previous discussion, I'm trying to reserve some space (such as 16-bytes)
before function to store the information about the function:

https://lore.kernel.org/bpf/CADxym3ZfHv_VdgopE5TBQxhO7RrPTVm83VW07c8bAywp404QPw@mail.gmail.com/T/#u

And let me describe it here again. For example, we have a function
"do_test", the layout is just like this:

-------------> 16-bytes
-------------> do_test
-------------> __fentry__(nop)

Then, we can alloc a memory, store some information that we
need, and store the pointer of this memory to "do_test - 8".
And then, we can get the function information with "ip - 8" in
bpf trampoline or ftrace handler.

After I dig into the code, I find that this space is already reserved
with the config:

CONFIG_MITIGATION_CALL_DEPTH_TRACKING
  CONFIG_CALL_THUNKS
    CALL_PADDING

And the reserved space before the function is 16 bytes. According
to my tests, 9 bytes is used by the call depth tracking if the CPU
support it, and the insn is just like this:

__pfx_do_test:
nop nop nop nop nop nop nop (7 bytes)
sarq (9 bytes)
do_test:
xxx

And all the calls to do_test will be redirected to __pfx_do_test + 7.
I think that there are still 7 bytes for me to use, which is enough.
In fact, 4 bytes is enough for me, as we can allocate a function
meta array, and store the index to the reserved space.

However, the other 5-bytes will be consumed if CFI_CLANG is
enabled, and the space is not enough anymore in this case, and
the insn will be like this:

__cfi_do_test:
mov (5byte)
nop nop (2 bytes)
sarq (9 bytes)
do_test:
xxx

A method that I think is that we can use such "function meta"
feature only if the call depth tracking or the CFI is not enabled.
(I'm not sure if the CFI is a commonly used feature.)

I would appreciate some advice :/

Thanks!
Menglong Dong

^ permalink raw reply	[flat|nested] 7+ messages in thread
[parent not found: <CADxym3Yop==sWx2q8448kYkDWcK=P7+fqeZLzyzk8D0GwZEV-A@mail.gmail.com>]

end of thread, other threads:[~2025-02-07  8:17 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-20 13:57 Idea for "function meta" Menglong Dong
2024-12-20 14:00 ` Peter Zijlstra
2024-12-25  3:26   ` Menglong Dong
2025-01-03 19:28     ` Alexei Starovoitov
2025-01-07 13:28       ` Menglong Dong
2025-02-07  8:16       ` Menglong Dong
     [not found] <CADxym3Yop==sWx2q8448kYkDWcK=P7+fqeZLzyzk8D0GwZEV-A@mail.gmail.com>
     [not found] ` <CAADnVQ+1mSHwUK4rZ_mJP7W72iSXgsVfazurYPRGi=3p5aBVdQ@mail.gmail.com>
2024-12-18  3:52   ` Menglong Dong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox