Skip to content

Commit

Permalink
fnargs: adjust up maximum args capture limits
Browse files Browse the repository at this point in the history
Allow user to request up to 64KB of data for arguments capture.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
  • Loading branch information
anakryiko committed Jul 24, 2024
1 parent 643125f commit 7d06541
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
9 changes: 4 additions & 5 deletions src/env.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ const char argp_program_doc[] =
struct env env = {
.ringbuf_map_sz = DEFAULT_RINGBUF_SZ,
.sessions_map_sz = DEFAULT_SESSIONS_SZ,
.args_max_total_args_size = MAX_FNARGS_TOTAL_ARGS_SZ,
.args_max_sized_arg_size = MAX_FNARGS_SIZED_ARG_SZ,
.args_max_str_arg_size = MAX_FNARGS_STR_ARG_SZ,
.args_max_total_args_size = DEFAULT_FNARGS_TOTAL_ARGS_SZ,
.args_max_sized_arg_size = DEFAULT_FNARGS_SIZED_ARG_SZ,
.args_max_str_arg_size = DEFAULT_FNARGS_STR_ARG_SZ,
.args_fmt_max_arg_width = DEFAULT_FNARGS_FMT_MAX_ARG_WIDTH,
};

Expand Down Expand Up @@ -694,8 +694,7 @@ void print_config_help_message(void)
int i;

log("It's possible to customize various retsnoop's internal implementation details.\n");
log("This can be done by specifying one or multiple extra parameters using\n");
log("--config KEY=VALUE CLI arguments.\n\n");
log("This can be done by specifying one or multiple extra parameters using --config KEY=VALUE CLI arguments.\n\n");

log("Supported configuration parameters:\n");
for (i = 0; i < ARRAY_SIZE(cfg_specs); i++) {
Expand Down
6 changes: 3 additions & 3 deletions src/fnargs.c
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ int prepare_fn_args_specs(int func_id, const struct mass_attacher_func_info *fin
t = btf_strip_mods_and_typedefs(finfo->btf, spec->btf_id, &btf_id);
if (btf_is_fixed_sized(finfo->btf, t) || btf_is_ptr(t)) {
true_len = btf_is_ptr(t) ? 8 : t->size;
data_len = min(true_len, MAX_FNARGS_SIZED_ARG_SZ);
data_len = min(true_len, env.args_max_sized_arg_size);

if (true_len <= 8 && is_arg_in_reg(reg_idx, &reg1_name)) {
/* fits in one register */
Expand Down Expand Up @@ -194,13 +194,13 @@ int prepare_fn_args_specs(int func_id, const struct mass_attacher_func_info *fin
if (btf_is_char(finfo->btf, t)) {
/* varlen string */
true_len = -1; /* mark that it's variable-length, for logging */
data_len = MAX_FNARGS_STR_ARG_SZ;
data_len = env.args_max_str_arg_size;
spec->arg_flags |= FUNC_ARG_PTR | FUNC_ARG_STR | data_len;
spec->pointee_btf_id = -1; /* special string marker */
dlog("str");
} else if (btf_is_fixed_sized(finfo->btf, t)) {
true_len = t->size;
data_len = min(true_len, MAX_FNARGS_SIZED_ARG_SZ);
data_len = min(true_len, env.args_max_sized_arg_size);
spec->arg_flags |= FUNC_ARG_PTR | data_len;
dlog("ptr_id=%d", spec->pointee_btf_id);
} else {
Expand Down
39 changes: 20 additions & 19 deletions src/retsnoop.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,39 +40,40 @@ enum func_flags {
};

#define MAX_FNARGS_ARG_SPEC_CNT 12
#define MAX_FNARGS_TOTAL_ARGS_SZ 3072 /* total captured args size for all args */
#define MAX_FNARGS_SIZED_ARG_SZ 256 /* maximum capture size for a single fixed-sized arg */
#define MAX_FNARGS_STR_ARG_SZ 256 /* maximum capture size for a signel string arg */
#define MAX_FNARGS_ANY_ARG_SZ \
(MAX_FNARGS_SIZED_ARG_SZ > MAX_FNARGS_STR_ARG_SZ \
? MAX_FNARGS_SIZED_ARG_SZ : MAX_FNARGS_STR_ARG_SZ)
#define MAX_FNARGS_TOTAL_ARGS_SZ (64 * 1024) /* maximum total captured args data size */
#define MAX_FNARGS_SIZED_ARG_SZ (16 * 1024) /* maximum capture size for a single fixed-sized arg */
#define MAX_FNARGS_STR_ARG_SZ (16 * 1024) /* maximum capture size for a signel string arg */

#define DEFAULT_FNARGS_TOTAL_ARGS_SZ 3072 /* default total captured args data size */
#define DEFAULT_FNARGS_SIZED_ARG_SZ 256 /* default capture size for a single fixed-sized arg */
#define DEFAULT_FNARGS_STR_ARG_SZ 256 /* default capture size for a signel string arg */

enum func_arg_flags {
/* lowest 12 bits */
FUNC_ARG_LEN_MASK = 0x0fff, /* 4KB bytes max */
/* lowest 16 bits */
FUNC_ARG_LEN_MASK = 0xffff, /* 64KB bytes max */

/* next 4 bits */
FUNC_ARG_REG = 0x1000, /* read specified register */
FUNC_ARG_REG_PAIR = 0x2000, /* read specified register */
FUNC_ARG_STACK = 0x4000, /* read stack at specified offset */
FUNC_ARG_PTR = 0x8000, /* pointer indirection */
FUNC_ARG_REG = 0x10000, /* read specified register */
FUNC_ARG_REG_PAIR = 0x20000, /* read specified register */
FUNC_ARG_STACK = 0x40000, /* read stack at specified offset */
FUNC_ARG_PTR = 0x80000, /* pointer indirection */

/* "varlen string" marker, uses impossible REG_PAIR + PTR combination */
FUNC_ARG_STR = FUNC_ARG_PTR | FUNC_ARG_REG_PAIR,

/* for REG_PAIR/REG we encode the first/only argument register index */
FUNC_ARG_REGIDX_MASK = 0x00ff0000, /* 1st argument register index */
FUNC_ARG_REGIDX_SHIFT = 16,
FUNC_ARG_REGIDX_MASK = 0x0ff00000, /* argument register index */
FUNC_ARG_REGIDX_SHIFT = 20,

/* for STACK we have one big offset */
FUNC_ARG_STACKOFF_MASK = 0xffff0000, /* stack offset */
FUNC_ARG_STACKOFF_SHIFT = 16,
FUNC_ARG_STACKOFF_MASK = 0xfff00000, /* stack offset */
FUNC_ARG_STACKOFF_SHIFT = 20,
FUNC_ARG_STACKOFF_MAX = FUNC_ARG_STACKOFF_MASK >> FUNC_ARG_STACKOFF_SHIFT,

/* special "skip arg" values, uses special REGIDX value */
FUNC_ARG_VARARG = 0x00fe0000,
FUNC_ARG_UNKN = 0x00fd0000,
FUNC_ARG_STACKOFF_2BIG = 0x00fc0000,
FUNC_ARG_VARARG = 0x0fe00000,
FUNC_ARG_UNKN = 0x0fd00000,
FUNC_ARG_STACKOFF_2BIG = 0x0fc00000,
};

struct func_info {
Expand Down

0 comments on commit 7d06541

Please sign in to comment.