Re: [PATCH bpf-next 4/4] bpf: Add selftests for local_storage

From: Andrii Nakryiko
Date: Mon Jun 01 2020 - 16:29:48 EST


On Tue, May 26, 2020 at 9:34 AM KP Singh <kpsingh@xxxxxxxxxxxx> wrote:
>
> From: KP Singh <kpsingh@xxxxxxxxxx>
>
> inode_local_storage:
>
> * Hook to the file_open and inode_unlink LSM hooks.
> * Create and unlink a temporary file.
> * Store some information in the inode's bpf_local_storage during
> file_open.
> * Verify that this information exists when the file is unlinked.
>
> sk_local_storage:
>
> * Hook to the socket_post_create and socket_bind LSM hooks.
> * Open and bind a socket and set the sk_storage in the
> socket_post_create hook using the start_server helper.
> * Verify if the information is set in the socket_bind hook.
>
> Signed-off-by: KP Singh <kpsingh@xxxxxxxxxx>
> ---
> .../bpf/prog_tests/test_local_storage.c | 60 ++++++++
> .../selftests/bpf/progs/local_storage.c | 139 ++++++++++++++++++
> 2 files changed, 199 insertions(+)
> create mode 100644 tools/testing/selftests/bpf/prog_tests/test_local_storage.c
> create mode 100644 tools/testing/selftests/bpf/progs/local_storage.c
>

[...]

> +struct dummy_storage {
> + __u32 value;
> +};
> +
> +struct {
> + __uint(type, BPF_MAP_TYPE_INODE_STORAGE);
> + __uint(map_flags, BPF_F_NO_PREALLOC);
> + __type(key, int);
> + __type(value, struct dummy_storage);
> +} inode_storage_map SEC(".maps");
> +
> +struct {
> + __uint(type, BPF_MAP_TYPE_SK_STORAGE);
> + __uint(map_flags, BPF_F_NO_PREALLOC | BPF_F_CLONE);
> + __type(key, int);
> + __type(value, struct dummy_storage);
> +} sk_storage_map SEC(".maps");
> +
> +/* Using vmlinux.h causes the generated BTF to be so big that the object
> + * load fails at btf__load.
> + */

That's first time I hear about such issue. Do you have an error log
from verifier?

Clang is smart enough to trim down used types to only those that are
actually necessary, so too big BTF shouldn't be a thing. But let's try
to dig into this and fix whatever issue it is, before giving up :)

> +struct sock {} __attribute__((preserve_access_index));
> +struct sockaddr {} __attribute__((preserve_access_index));
> +struct socket {
> + struct sock *sk;
> +} __attribute__((preserve_access_index));
> +
> +struct inode {} __attribute__((preserve_access_index));
> +struct dentry {
> + struct inode *d_inode;
> +} __attribute__((preserve_access_index));
> +struct file {
> + struct inode *f_inode;
> +} __attribute__((preserve_access_index));
> +
> +

[...]