From af02a147ba5a56d61fe6248ea453472dfefcec3a Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Tue, 2 Jul 2019 11:49:15 +0000 Subject: [PATCH] bpf: implement decoding of BPF_MAP_FREEZE command BPF_MAP_FREEZE command was introduced by Linux commit v5.2-rc1~133^2~193^2~12^2~12. * bpf_attr.h (struct BPF_MAP_FREEZE_struct): New type. (BPF_MAP_FREEZE_struct_size, expected_BPF_MAP_FREEZE_struct_size): New macros. * bpf.c (BEGIN_BPF_CMD_DECODER(BPF_MAP_FREEZE)): New bpf command decoder. (SYS_FUNC(bpf)) : Add BPF_CMD_ENTRY(BPF_MAP_FREEZE). * NEWS: Mention this. * tests/bpf.c (union bpf_attr_data): Add BPF_ATTR_DATA_FIELD(BPF_MAP_FREEZE). (BPF_MAP_FREEZE_checks): New checks array. (main) : Add CHK(BPF_MAP_FREEZE). --- NEWS | 2 +- bpf.c | 7 +++++++ bpf_attr.h | 8 ++++++++ tests/bpf.c | 10 ++++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index cb1c5450..776bbec5 100644 --- a/NEWS +++ b/NEWS @@ -4,7 +4,7 @@ Noteworthy changes in release ?.? (????-??-??) * Improvements * Implemented decoding of open_tree, move_mount, fsopen, fsconfig, fsmount, and fspick syscalls. - * Enhanced decoding of clone syscall. + * Enhanced decoding of bpf and clone syscalls. * Updated lists of AT_*, AUDIT_*, BPF_*, CLONE_*, ETH_*, KEY_*, KVM_*, TIPC_*, and V4L2_* constants. diff --git a/bpf.c b/bpf.c index 420b4402..5329fc2f 100644 --- a/bpf.c +++ b/bpf.c @@ -261,6 +261,12 @@ BEGIN_BPF_CMD_DECODER(BPF_MAP_GET_NEXT_KEY) } END_BPF_CMD_DECODER(RVAL_DECODED) +BEGIN_BPF_CMD_DECODER(BPF_MAP_FREEZE) +{ + PRINT_FIELD_FD("{", attr, map_fd, tcp); +} +END_BPF_CMD_DECODER(RVAL_DECODED) + BEGIN_BPF_CMD_DECODER(BPF_PROG_LOAD) { PRINT_FIELD_XVAL_INDEX("{", attr, prog_type, bpf_prog_types, @@ -927,6 +933,7 @@ SYS_FUNC(bpf) BPF_CMD_ENTRY(BPF_BTF_GET_FD_BY_ID), BPF_CMD_ENTRY(BPF_TASK_FD_QUERY), BPF_CMD_ENTRY(BPF_MAP_LOOKUP_AND_DELETE_ELEM), + BPF_CMD_ENTRY(BPF_MAP_FREEZE), }; const unsigned int cmd = tcp->u_arg[0]; diff --git a/bpf_attr.h b/bpf_attr.h index 5c5eee41..21b4cd76 100644 --- a/bpf_attr.h +++ b/bpf_attr.h @@ -95,6 +95,14 @@ struct BPF_MAP_GET_NEXT_KEY_struct { sizeof(struct BPF_MAP_GET_NEXT_KEY_struct) # define expected_BPF_MAP_GET_NEXT_KEY_struct_size 24 +struct BPF_MAP_FREEZE_struct { + uint32_t map_fd; +}; + +# define BPF_MAP_FREEZE_struct_size \ + sizeof(struct BPF_MAP_FREEZE_struct) +# define expected_BPF_MAP_FREEZE_struct_size 4 + struct BPF_PROG_LOAD_struct { uint32_t prog_type; uint32_t insn_cnt; diff --git a/tests/bpf.c b/tests/bpf.c index 8905d737..08f78964 100644 --- a/tests/bpf.c +++ b/tests/bpf.c @@ -74,6 +74,7 @@ union bpf_attr_data { BPF_ATTR_DATA_FIELD(BPF_BTF_LOAD); BPF_ATTR_DATA_FIELD(BPF_BTF_GET_FD_BY_ID); BPF_ATTR_DATA_FIELD(BPF_TASK_FD_QUERY); + BPF_ATTR_DATA_FIELD(BPF_MAP_FREEZE); char char_data[256]; }; @@ -496,6 +497,14 @@ static const struct bpf_attr_check BPF_MAP_GET_NEXT_KEY_checks[] = { } }; +static const struct bpf_attr_check BPF_MAP_FREEZE_checks[] = { + { + .data = { .BPF_MAP_FREEZE_data = { .map_fd = -1 } }, + .size = offsetofend(struct BPF_MAP_FREEZE_struct, map_fd), + .str = "map_fd=-1" + } +}; + static const struct bpf_insn insns[] = { { .code = 0x95, @@ -1231,6 +1240,7 @@ main(void) CHK(BPF_BTF_GET_FD_BY_ID), CHK(BPF_TASK_FD_QUERY), CHK(BPF_MAP_LOOKUP_AND_DELETE_ELEM), + CHK(BPF_MAP_FREEZE), }; page_size = get_page_size(); -- 2.40.0