Re: CORE feature request: support checking field type directly

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

 



On Thu, Jan 12, 2023 at 2:18 PM Hao Luo <haoluo@xxxxxxxxxx> wrote:
>
> Hi all,
>
> Feature request:
>
> To support checking the type of a specific field directly.
>
> Background:
>
> Currently, As far as I know, CORE is able to check a field’s
> existence, offset, size and signedness, but not the field’s type
> directly.
>
> There are changes that convert a field from a scalar type to a struct
> type, without changing the field’s name, offset or size. In that case,
> it is currently difficult to use CORE to check such changes. For a
> concrete example,
>
> Commit 94a9717b3c (“locking/rwsem: Make rwsem->owner an atomic_long_t”)
>
> Changed the type of rw_semaphore::owner from tast_struct * to
> atomic_long_t. In that change, the field name, offset and size remain
> the same. But the BPF program code used to extract the value is
> different. For the kernel where the field is a pointer, we can write:
>
> sem->owner
>
> While in the kernel where the field is an atomic, we need to write:
>
> sem->owner.counter.
>
> It would be great to be able to check a field’s type directly.
> Probably something like:
>
> #include “vmlinux.h”
>
> struct rw_semaphore__old {
>         struct task_struct *owner;
> };
>
> struct rw_semaphore__new {
>         atomic_long_t owner;
> };
>
> u64 owner;
> if (bpf_core_field_type_is(sem->owner, struct task_struct *)) {
>         struct rw_semaphore__old *old = (struct rw_semaphore__old *)sem;
>         owner = (u64)sem->owner;
> } else if (bpf_core_field_type_is(sem->owner, atomic_long_t)) {
>         struct rw_semaphore__new *new = (struct rw_semaphore__new *)sem;
>         owner = new->owner.counter;
> }
>

Have you tried bpf_core_type_matches()? It seems like exactly what you
are looking for? See [0] for logic of what constitutes "a match".

  [0] https://github.com/libbpf/libbpf/blob/master/src/relo_core.c#L1517-L1543

> Hao




[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