All of lore.kernel.org
 help / color / mirror / Atom feed
* CORE feature request: support checking field type directly
@ 2023-01-12 22:18 Hao Luo
  2023-01-13 23:41 ` Andrii Nakryiko
  2023-01-17 21:56 ` Daniel Müller
  0 siblings, 2 replies; 13+ messages in thread
From: Hao Luo @ 2023-01-12 22:18 UTC (permalink / raw)
  To: bpf
  Cc: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Song Liu, Yonghong Song, KP Singh,
	Stanislav Fomichev, Jiri Olsa, John Fastabend

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;
}

Hao

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2023-01-31 19:58 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-12 22:18 CORE feature request: support checking field type directly Hao Luo
2023-01-13 23:41 ` Andrii Nakryiko
2023-01-14  1:06   ` Hao Luo
2023-01-14  1:14     ` Andrii Nakryiko
2023-01-14  2:19       ` Hao Luo
2023-01-14  2:44         ` Andrii Nakryiko
2023-01-17 18:45           ` Hao Luo
2023-01-17 21:56 ` Daniel Müller
2023-01-17 22:21   ` Daniel Müller
2023-01-18  0:55     ` Hao Luo
2023-01-31  6:06       ` Namhyung Kim
2023-01-31 16:46         ` Daniel Müller
2023-01-31 19:58           ` Namhyung Kim

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.