Re: CORE feature request: support checking field type directly

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

 



On Fri, Jan 13, 2023 at 6:20 PM Hao Luo <haoluo@xxxxxxxxxx> wrote:
>
> On Fri, Jan 13, 2023 at 5:14 PM Andrii Nakryiko
> <andrii.nakryiko@xxxxxxxxx> wrote:
> >
> > On Fri, Jan 13, 2023 at 5:06 PM Hao Luo <haoluo@xxxxxxxxxx> wrote:
> > >
> > > On Fri, Jan 13, 2023 at 3:41 PM Andrii Nakryiko
> > > <andrii.nakryiko@xxxxxxxxx> wrote:
> > > >
> <...>
> > > >
> > > > 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".
> > > >
> > >
> > > It seems bpf_core_type_matches() is for the userspace code. I'm
> >
> > It's in the same family as bpf_type_{exists,size}() and
> > bpf_field_{exists,size,offset}(). It's purely BPF-side. Please grep
> > for bpf_core_type_matches() in selftests/bpf.
> >
> > > looking for type checking in the BPF code. We probably don't need to
> > > check type equivalence, just comparing the btf_id of the field's type
> > > and the btf_id of a target type may be sufficient.
> >
> > With the example above something like below should work:
> >
> > struct rw_semaphore__old {
> >         struct task_struct *owner;
> > };
> >
> > struct rw_semaphore__new {
> >         atomic_long_t owner;
> > };
> >
> > u64 owner;
> > if (bpf_core_type_matches(struct rw_semaphore__old) /* owner is
> > task_struct pointer */) {
> >         struct rw_semaphore__old *old = (struct rw_semaphore__old *)sem;
> >         owner = (u64)sem->owner;
> > } else if (bpf_core_type_matches(struct rw_semaphore__old) /* owner
> > field is atomic_long_t */) {
> >         struct rw_semaphore__new *new = (struct rw_semaphore__new *)sem;
> >         owner = new->owner.counter;
> > }
> >
> > >
> > > The commit 94a9717b3c (“locking/rwsem: Make rwsem->owner an
> > > atomic_long_t”) is rare, but the 'owner' field is useful for tracking
> > > the owner of a kernel lock.
> >
> > We implemented bpf_core_type_matches() to detect tracepoint changes,
> > which is equivalent (if not harder) use case. Give it a try.
> >
>
> Thanks Andrii for the pointer. It's still not working. I got the
> following error when loading:
>
> libbpf: prog 'on_contention_begin': relo #1: parsing [43] struct
> rw_semaphore__old + 0 failed: -22
> libbpf: prog 'on_contention_begin': relo #1: failed to relocate: -22
> libbpf: failed to perform CO-RE relocations: -22
>
> I'll dig a little more next week.

You need triple underscore between old and new suffixes, see [0] for
ignored suffix rule.

  [0] https://nakryiko.com/posts/bpf-core-reference-guide/#handling-incompatible-field-and-type-changes




[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