From mboxrd@z Thu Jan 1 00:00:00 1970 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=-9.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham 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 933BBC282D8 for ; Sat, 2 Feb 2019 00:14:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5ACBC20863 for ; Sat, 2 Feb 2019 00:14:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=fb.com header.i=@fb.com header.b="rMQLH7++" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726660AbfBBAOV (ORCPT ); Fri, 1 Feb 2019 19:14:21 -0500 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:57824 "EHLO mx0b-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726481AbfBBAOU (ORCPT ); Fri, 1 Feb 2019 19:14:20 -0500 Received: from pps.filterd (m0109332.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x120Dse0027806 for ; Fri, 1 Feb 2019 16:14:19 -0800 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-type; s=facebook; bh=pRUzCbJK0Rmrv84x5wyLO5FmrTedSJxCAJ+fxCZyR2A=; b=rMQLH7++DviBHNfrWQsYSifU0LcSS/ub3iyPlEXApFQSON7CHXUjfM2QDZlZ7pPr3NNz oCHxfn9S1Jh/ghon6x5E/Qg01+UVQzLPUnwX1x9n7vwJnSbSyeJJJ/cXKH7OseJGSBs4 5+s1H2r2mJREFEMwCwXMXLway2yySt5z7hQ= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 2qcxv98985-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Fri, 01 Feb 2019 16:14:19 -0800 Received: from mx-out.facebook.com (2620:10d:c081:10::13) by mail.thefacebook.com (2620:10d:c081:35::128) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA) id 15.1.1531.3; Fri, 1 Feb 2019 16:14:17 -0800 Received: by devbig003.ftw2.facebook.com (Postfix, from userid 128203) id 0657E3702AB9; Fri, 1 Feb 2019 16:14:15 -0800 (PST) Smtp-Origin-Hostprefix: devbig From: Yonghong Song Smtp-Origin-Hostname: devbig003.ftw2.facebook.com To: Arnaldo Carvalho de Melo , Magnus Karlsson , CC: Alexei Starovoitov , Daniel Borkmann , , Yonghong Song Smtp-Origin-Cluster: ftw2c04 Subject: [PATCH bpf-next v4 2/3] tools/bpf: print out btf log at LIBBPF_WARN level Date: Fri, 1 Feb 2019 16:14:15 -0800 Message-ID: <20190202001415.3178420-1-yhs@fb.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190202001413.3178000-1-yhs@fb.com> References: <20190202001413.3178000-1-yhs@fb.com> X-FB-Internal: Safe MIME-Version: 1.0 Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-02-01_18:,, signatures=0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Currently, the btf log is allocated and printed out in case of error at LIBBPF_DEBUG level. Such logs from kernel are very important for debugging. For example, bpf syscall BPF_PROG_LOAD command can get verifier logs back to user space. In function load_program() of libbpf.c, the log buffer is allocated unconditionally and printed out at pr_warning() level. Let us do the similar thing here for btf. Allocate buffer unconditionally and print out error logs at pr_warning() level. This can reduce one global function and optimize for common situations where pr_warning() is activated either by default or by user supplied debug output function. Signed-off-by: Yonghong Song --- tools/lib/bpf/btf.c | 19 +++++++++---------- tools/lib/bpf/libbpf.c | 10 ---------- tools/lib/bpf/libbpf_util.h | 2 -- 3 files changed, 9 insertions(+), 22 deletions(-) diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c index 93e792b82242..51a0db05bf80 100644 --- a/tools/lib/bpf/btf.c +++ b/tools/lib/bpf/btf.c @@ -377,16 +377,15 @@ struct btf *btf__new(__u8 *data, __u32 size) btf->fd = -1; - if (libbpf_print_level_available(LIBBPF_DEBUG)) { - log_buf = malloc(BPF_LOG_BUF_SIZE); - if (!log_buf) { - err = -ENOMEM; - goto done; - } - *log_buf = 0; - log_buf_size = BPF_LOG_BUF_SIZE; + log_buf = malloc(BPF_LOG_BUF_SIZE); + if (!log_buf) { + err = -ENOMEM; + goto done; } + *log_buf = 0; + log_buf_size = BPF_LOG_BUF_SIZE; + btf->data = malloc(size); if (!btf->data) { err = -ENOMEM; @@ -401,9 +400,9 @@ struct btf *btf__new(__u8 *data, __u32 size) if (btf->fd == -1) { err = -errno; - pr_debug("Error loading BTF: %s(%d)\n", strerror(errno), errno); + pr_warning("Error loading BTF: %s(%d)\n", strerror(errno), errno); if (log_buf && *log_buf) - pr_debug("%s\n", log_buf); + pr_warning("%s\n", log_buf); goto done; } diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index eeba77b695ad..0354af03b038 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -98,16 +98,6 @@ void libbpf_print(enum libbpf_print_level level, const char *format, ...) va_end(args); } -bool libbpf_print_level_available(enum libbpf_print_level level) -{ - if (level == LIBBPF_WARN) - return !!__pr_warning; - else if (level == LIBBPF_INFO) - return !!__pr_info; - else - return !!__pr_debug; -} - #define STRERR_BUFSIZE 128 #define CHECK_ERR(action, err, out) do { \ diff --git a/tools/lib/bpf/libbpf_util.h b/tools/lib/bpf/libbpf_util.h index 0fdc3b1d0e33..81ecda0cb9c9 100644 --- a/tools/lib/bpf/libbpf_util.h +++ b/tools/lib/bpf/libbpf_util.h @@ -14,8 +14,6 @@ extern void libbpf_print(enum libbpf_print_level level, const char *format, ...) __attribute__((format(printf, 2, 3))); -extern bool libbpf_print_level_available(enum libbpf_print_level level); - #define __pr(level, fmt, ...) \ do { \ libbpf_print(level, "libbpf: " fmt, ##__VA_ARGS__); \ -- 2.17.1