Skip to content

Commit 88b4130

Browse files
AsphalttKernel Patches Daemon
authored andcommitted
bpf: Add common attr support for btf_load
The log buffer of common attributes would be confusing with the one in 'union bpf_attr' for BPF_BTF_LOAD. In order to clarify the usage of these two log buffers, they both can be used for logging if: * They are same, including 'log_buf', 'log_level' and 'log_size'. * One of them is missing, then another one will be used for logging. If they both have 'log_buf' but they are not same totally, return -EUSERS. Signed-off-by: Leon Hwang <[email protected]>
1 parent e5dff25 commit 88b4130

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

kernel/bpf/syscall.c

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6151,11 +6151,37 @@ static int copy_prog_load_log_true_size(union bpf_attr *attr, bpfptr_t uattr, un
61516151
return 0;
61526152
}
61536153

6154-
static int copy_btf_load_log_true_size(union bpf_attr *attr, bpfptr_t uattr, unsigned int size)
6154+
static int check_btf_load_log_attrs(union bpf_attr *attr, struct bpf_common_attr *common_attrs,
6155+
bool *log_common_attrs)
6156+
{
6157+
int err;
6158+
6159+
err = check_log_attrs(attr->btf_log_buf, attr->btf_log_size, attr->btf_log_level,
6160+
common_attrs);
6161+
if (err)
6162+
return err;
6163+
6164+
if (!attr->btf_log_buf && common_attrs->log_buf) {
6165+
*log_common_attrs = true;
6166+
attr->btf_log_buf = common_attrs->log_buf;
6167+
attr->btf_log_size = common_attrs->log_size;
6168+
attr->btf_log_level = common_attrs->log_level;
6169+
}
6170+
6171+
return 0;
6172+
}
6173+
6174+
static int copy_btf_load_log_true_size(union bpf_attr *attr, bpfptr_t uattr, unsigned int size,
6175+
struct bpf_common_attr *common_attrs, bpfptr_t uattr_common,
6176+
unsigned int size_common, bool log_common_attrs)
61556177
{
61566178
if (!attr->btf_log_true_size)
61576179
return 0;
61586180

6181+
if (log_common_attrs)
6182+
return __copy_common_attr_log_true_size(uattr_common, size_common,
6183+
&attr->btf_log_true_size);
6184+
61596185
if (size >= offsetofend(union bpf_attr, btf_log_true_size) &&
61606186
copy_to_bpfptr_offset(uattr, offsetof(union bpf_attr, btf_log_true_size),
61616187
&attr->btf_log_true_size, sizeof(attr->btf_log_true_size)))
@@ -6270,9 +6296,13 @@ static int __sys_bpf(enum bpf_cmd cmd, bpfptr_t uattr, unsigned int size,
62706296
err = bpf_raw_tracepoint_open(&attr);
62716297
break;
62726298
case BPF_BTF_LOAD:
6299+
err = check_btf_load_log_attrs(&attr, &common_attrs, &log_common_attrs);
6300+
if (err)
6301+
break;
62736302
attr.btf_log_true_size = 0;
62746303
err = bpf_btf_load(&attr, uattr);
6275-
ret = copy_btf_load_log_true_size(&attr, uattr, size);
6304+
ret = copy_btf_load_log_true_size(&attr, uattr, size, &common_attrs, uattr_common,
6305+
size_common, log_common_attrs);
62766306
err = ret ? ret : err;
62776307
break;
62786308
case BPF_BTF_GET_FD_BY_ID:

0 commit comments

Comments
 (0)