]> granicus.if.org Git - strace/commitdiff
bpf: implement decoding of BPF_MAP_FREEZE command
authorDmitry V. Levin <ldv@altlinux.org>
Tue, 2 Jul 2019 11:49:15 +0000 (11:49 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Tue, 2 Jul 2019 11:49:15 +0000 (11:49 +0000)
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)) <bpf_cmd_decoders[]>: 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) <checks>: Add CHK(BPF_MAP_FREEZE).

NEWS
bpf.c
bpf_attr.h
tests/bpf.c

diff --git a/NEWS b/NEWS
index cb1c545068739e0f0ba9bb831a988082ce7cfafe..776bbec5b7d5b5ad45ce953f2473b382f212f656 100644 (file)
--- 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 420b44026eb832e83465e3e0f980302e2c01250d..5329fc2fe47e2cbc3a4521ebd70c803fdfc86147 100644 (file)
--- 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];
index 5c5eee410c8a037d304af5b0f4a166f5ca028e57..21b4cd767d3d352995210d4244e8e8048f207f2e 100644 (file)
@@ -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;
index 8905d7372bba4e925a83204811cd6b8230f11634..08f78964744eaddd030d0a8109f667b487b1f504 100644 (file)
@@ -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();