提交 335ff499 编写于 作者: D Dave Marchevsky 提交者: Alexei Starovoitov

bpf: Merge printk and seq_printf VARARG max macros

MAX_SNPRINTF_VARARGS and MAX_SEQ_PRINTF_VARARGS are used by bpf helpers
bpf_snprintf and bpf_seq_printf to limit their varargs. Both call into
bpf_bprintf_prepare for print formatting logic and have convenience
macros in libbpf (BPF_SNPRINTF, BPF_SEQ_PRINTF) which use the same
helper macros to convert varargs to a byte array.

Changing shared functionality to support more varargs for either bpf
helper would affect the other as well, so let's combine the _VARARGS
macros to make this more obvious.
Signed-off-by: NDave Marchevsky <davemarchevsky@fb.com>
Signed-off-by: NAlexei Starovoitov <ast@kernel.org>
Acked-by: NAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20210917182911.2426606-2-davemarchevsky@fb.com
上级 af54faab
...@@ -2216,6 +2216,8 @@ int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type t, ...@@ -2216,6 +2216,8 @@ int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type t,
struct btf_id_set; struct btf_id_set;
bool btf_id_set_contains(const struct btf_id_set *set, u32 id); bool btf_id_set_contains(const struct btf_id_set *set, u32 id);
#define MAX_BPRINTF_VARARGS 12
int bpf_bprintf_prepare(char *fmt, u32 fmt_size, const u64 *raw_args, int bpf_bprintf_prepare(char *fmt, u32 fmt_size, const u64 *raw_args,
u32 **bin_buf, u32 num_args); u32 **bin_buf, u32 num_args);
void bpf_bprintf_cleanup(void); void bpf_bprintf_cleanup(void);
......
...@@ -979,15 +979,13 @@ int bpf_bprintf_prepare(char *fmt, u32 fmt_size, const u64 *raw_args, ...@@ -979,15 +979,13 @@ int bpf_bprintf_prepare(char *fmt, u32 fmt_size, const u64 *raw_args,
return err; return err;
} }
#define MAX_SNPRINTF_VARARGS 12
BPF_CALL_5(bpf_snprintf, char *, str, u32, str_size, char *, fmt, BPF_CALL_5(bpf_snprintf, char *, str, u32, str_size, char *, fmt,
const void *, data, u32, data_len) const void *, data, u32, data_len)
{ {
int err, num_args; int err, num_args;
u32 *bin_args; u32 *bin_args;
if (data_len % 8 || data_len > MAX_SNPRINTF_VARARGS * 8 || if (data_len % 8 || data_len > MAX_BPRINTF_VARARGS * 8 ||
(data_len && !data)) (data_len && !data))
return -EINVAL; return -EINVAL;
num_args = data_len / 8; num_args = data_len / 8;
......
...@@ -414,15 +414,13 @@ const struct bpf_func_proto *bpf_get_trace_printk_proto(void) ...@@ -414,15 +414,13 @@ const struct bpf_func_proto *bpf_get_trace_printk_proto(void)
return &bpf_trace_printk_proto; return &bpf_trace_printk_proto;
} }
#define MAX_SEQ_PRINTF_VARARGS 12
BPF_CALL_5(bpf_seq_printf, struct seq_file *, m, char *, fmt, u32, fmt_size, BPF_CALL_5(bpf_seq_printf, struct seq_file *, m, char *, fmt, u32, fmt_size,
const void *, data, u32, data_len) const void *, data, u32, data_len)
{ {
int err, num_args; int err, num_args;
u32 *bin_args; u32 *bin_args;
if (data_len & 7 || data_len > MAX_SEQ_PRINTF_VARARGS * 8 || if (data_len & 7 || data_len > MAX_BPRINTF_VARARGS * 8 ||
(data_len && !data)) (data_len && !data))
return -EINVAL; return -EINVAL;
num_args = data_len / 8; num_args = data_len / 8;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册