From patchwork Mon Sep 20 15:11:11 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Marchevsky X-Patchwork-Id: 12505659 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65376C433EF for ; Mon, 20 Sep 2021 15:11:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4313660ED7 for ; Mon, 20 Sep 2021 15:11:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241330AbhITPNJ (ORCPT ); Mon, 20 Sep 2021 11:13:09 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:42964 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241299AbhITPNG (ORCPT ); Mon, 20 Sep 2021 11:13:06 -0400 Received: from pps.filterd (m0109333.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 18KALl1Q019039 for ; Mon, 20 Sep 2021 08:11:40 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=Wfo4D6bGx0psxdGz31HyFVLjxtFxNOZejRJ31RUGuTc=; b=J9vcfagdXeTKIL9162ifOTgn0K1Qn+1gcuWwWTNMEHBM7BCT3FTa3j3AdAH/LsEYuRZF kKNtrjeaC8o4aLqpzqTqlQ9sYpf5EkJLASrQrBERwdoUb2y6EBPLrqXIr/SOhanyPqFE 3x/YeyGxGxQDcpbAof9JwalixrXPnb7MRrg= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 3b6d2k471p-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Mon, 20 Sep 2021 08:11:40 -0700 Received: from intmgw001.37.frc1.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:83::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.14; Mon, 20 Sep 2021 08:11:35 -0700 Received: by devbig030.frc3.facebook.com (Postfix, from userid 158236) id D0E3D6E18CBE; Mon, 20 Sep 2021 08:11:25 -0700 (PDT) From: Dave Marchevsky To: CC: , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Yonghong Song , Dave Marchevsky Subject: [RFC PATCH bpf-next 1/2] bpf: add verifier stats to bpf_prog_info and fdinfo Date: Mon, 20 Sep 2021 08:11:11 -0700 Message-ID: <20210920151112.3770991-2-davemarchevsky@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210920151112.3770991-1-davemarchevsky@fb.com> References: <20210920151112.3770991-1-davemarchevsky@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-FB-Source: Intern X-Proofpoint-ORIG-GUID: 8GNxg9_oJKJZaOu415Qc9nJTCU4DNsR6 X-Proofpoint-GUID: 8GNxg9_oJKJZaOu415Qc9nJTCU4DNsR6 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.391,FMLib:17.0.607.475 definitions=2021-09-20_07,2021-09-20_01,2020-04-07_01 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 malwarescore=0 mlxlogscore=999 bulkscore=0 phishscore=0 impostorscore=0 adultscore=0 mlxscore=0 lowpriorityscore=0 suspectscore=0 priorityscore=1501 clxscore=1015 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2109030001 definitions=main-2109200098 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC These stats are currently printed in the verifier log and not stored anywhere. To ease consumption of this data, add a bpf_prog_verif_stats struct to bpf_prog_aux so they can be exposed via BPF_OBJ_GET_INFO_BY_FD and fdinfo. Signed-off-by: Dave Marchevsky --- include/linux/bpf.h | 1 + include/uapi/linux/bpf.h | 10 ++++++++++ kernel/bpf/syscall.c | 20 ++++++++++++++++++-- kernel/bpf/verifier.c | 13 +++++++++++++ tools/include/uapi/linux/bpf.h | 10 ++++++++++ 5 files changed, 52 insertions(+), 2 deletions(-) diff --git a/include/linux/bpf.h b/include/linux/bpf.h index b6c45a6cbbba..206c19b253b7 100644 --- a/include/linux/bpf.h +++ b/include/linux/bpf.h @@ -876,6 +876,7 @@ struct bpf_prog_aux { struct bpf_kfunc_desc_tab *kfunc_tab; u32 size_poke_tab; struct bpf_ksym ksym; + struct bpf_prog_verif_stats verif_stats; const struct bpf_prog_ops *ops; struct bpf_map **used_maps; struct mutex used_maps_mutex; /* mutex for used_maps and used_map_cnt */ diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 6fc59d61937a..cb0fa49e62d7 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -5576,6 +5576,15 @@ struct sk_reuseport_md { #define BPF_TAG_SIZE 8 +struct bpf_prog_verif_stats { + __u64 verification_time; + __u32 insn_processed; + __u32 max_states_per_insn; + __u32 total_states; + __u32 peak_states; + __u32 longest_mark_read_walk; +}; + struct bpf_prog_info { __u32 type; __u32 id; @@ -5613,6 +5622,7 @@ struct bpf_prog_info { __u64 run_time_ns; __u64 run_cnt; __u64 recursion_misses; + struct bpf_prog_verif_stats verif_stats; } __attribute__((aligned(8))); struct bpf_map_info { diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index 4e50c0bfdb7d..0fa95ebd4276 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -1836,9 +1836,11 @@ static void bpf_prog_show_fdinfo(struct seq_file *m, struct file *filp) { const struct bpf_prog *prog = filp->private_data; char prog_tag[sizeof(prog->tag) * 2 + 1] = { }; + struct bpf_prog_verif_stats *verif_stats; struct bpf_prog_stats stats; bpf_prog_get_stats(prog, &stats); + verif_stats = &prog->aux->verif_stats; bin2hex(prog_tag, prog->tag, sizeof(prog->tag)); seq_printf(m, "prog_type:\t%u\n" @@ -1848,7 +1850,13 @@ static void bpf_prog_show_fdinfo(struct seq_file *m, struct file *filp) "prog_id:\t%u\n" "run_time_ns:\t%llu\n" "run_cnt:\t%llu\n" - "recursion_misses:\t%llu\n", + "recursion_misses:\t%llu\n" + "verification_time:\t%llu\n" + "verif_insn_processed:\t%u\n" + "verif_max_states_per_insn:\t%u\n" + "verif_total_states:\t%u\n" + "verif_peak_states:\t%u\n" + "verif_longest_mark_read_walk:\t%u\n", prog->type, prog->jited, prog_tag, @@ -1856,7 +1864,13 @@ static void bpf_prog_show_fdinfo(struct seq_file *m, struct file *filp) prog->aux->id, stats.nsecs, stats.cnt, - stats.misses); + stats.misses, + verif_stats->verification_time, + verif_stats->insn_processed, + verif_stats->max_states_per_insn, + verif_stats->total_states, + verif_stats->peak_states, + verif_stats->longest_mark_read_walk); } #endif @@ -3625,6 +3639,8 @@ static int bpf_prog_get_info_by_fd(struct file *file, info.run_cnt = stats.cnt; info.recursion_misses = stats.misses; + info.verif_stats = prog->aux->verif_stats; + if (!bpf_capable()) { info.jited_prog_len = 0; info.xlated_prog_len = 0; diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index e76b55917905..97cd3b71d5ae 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -13245,6 +13245,18 @@ static void print_verification_stats(struct bpf_verifier_env *env) env->peak_states, env->longest_mark_read_walk); } +static void populate_aux_verif_stats(struct bpf_verifier_env *env) +{ + struct bpf_prog_verif_stats *verif_stats = &env->prog->aux->verif_stats; + + verif_stats->verification_time = env->verification_time; + verif_stats->insn_processed = env->insn_processed; + verif_stats->max_states_per_insn = env->max_states_per_insn; + verif_stats->total_states = env->total_states; + verif_stats->peak_states = env->peak_states; + verif_stats->longest_mark_read_walk = env->longest_mark_read_walk; +} + static int check_struct_ops_btf_id(struct bpf_verifier_env *env) { const struct btf_type *t, *func_proto; @@ -13826,6 +13838,7 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr) env->verification_time = ktime_get_ns() - start_time; print_verification_stats(env); + populate_aux_verif_stats(env); if (log->level && bpf_verifier_log_full(log)) ret = -ENOSPC; diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index 6fc59d61937a..cb0fa49e62d7 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -5576,6 +5576,15 @@ struct sk_reuseport_md { #define BPF_TAG_SIZE 8 +struct bpf_prog_verif_stats { + __u64 verification_time; + __u32 insn_processed; + __u32 max_states_per_insn; + __u32 total_states; + __u32 peak_states; + __u32 longest_mark_read_walk; +}; + struct bpf_prog_info { __u32 type; __u32 id; @@ -5613,6 +5622,7 @@ struct bpf_prog_info { __u64 run_time_ns; __u64 run_cnt; __u64 recursion_misses; + struct bpf_prog_verif_stats verif_stats; } __attribute__((aligned(8))); struct bpf_map_info {