Idea for "function meta"

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

 



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@xxxxxxxxxxxxxx/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




[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