From patchwork Sat Aug 21 02:58:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Marchevsky X-Patchwork-Id: 12450791 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=-19.5 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=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 D2237C432BE for ; Sat, 21 Aug 2021 02:59:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BB9F8610A3 for ; Sat, 21 Aug 2021 02:59:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240512AbhHUC7z (ORCPT ); Fri, 20 Aug 2021 22:59:55 -0400 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]:42636 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231847AbhHUC7z (ORCPT ); Fri, 20 Aug 2021 22:59:55 -0400 Received: from pps.filterd (m0089730.ppops.net [127.0.0.1]) by m0089730.ppops.net (8.16.0.43/8.16.0.43) with SMTP id 17L2nqW7004027 for ; Fri, 20 Aug 2021 19:59:16 -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=kjxoTvvbtdKtm++ybFFEOg5xUoaDxGTFS2ZQmkmKJ70=; b=aPbHsuuDmjBPan4LhD/uJRbKYxnnRywY3faenm/vXjRmcxOu6F4+Q3OGxgyS0ely58Wc TGyEa0dc+nHhFx5ZCTMYLvcUzx40CMhDwgDMLJdcn9eg7iaLvPEKidCRRKXebmoMcekU qkPVsDczHAJkULN1KNfkIx4X20V6+KYmyzo= Received: from maileast.thefacebook.com ([163.114.130.16]) by m0089730.ppops.net with ESMTP id 3ajjxt1pt7-13 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Fri, 20 Aug 2021 19:59:16 -0700 Received: from intmgw001.25.frc3.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:83::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Fri, 20 Aug 2021 19:59:14 -0700 Received: by devbig030.frc3.facebook.com (Postfix, from userid 158236) id 1421057300B2; Fri, 20 Aug 2021 19:59:10 -0700 (PDT) From: Dave Marchevsky To: CC: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Yonghong Song , Florent Revest , , , Dave Marchevsky Subject: [PATCH bpf-next 3/5] libbpf: Add bpf_vprintk convenience macro Date: Fri, 20 Aug 2021 19:58:35 -0700 Message-ID: <20210821025837.1614098-4-davemarchevsky@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210821025837.1614098-1-davemarchevsky@fb.com> References: <20210821025837.1614098-1-davemarchevsky@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-FB-Source: Intern X-Proofpoint-ORIG-GUID: 9HYk7wSyOWjdbZZL-hKelMqLSMYU0tGO X-Proofpoint-GUID: 9HYk7wSyOWjdbZZL-hKelMqLSMYU0tGO X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-08-20_11:2021-08-20,2021-08-20 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 malwarescore=0 priorityscore=1501 bulkscore=0 adultscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxlogscore=959 suspectscore=0 mlxscore=0 phishscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108210016 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net bpf_vprintk functions similarly to BPF_SEQ_PRINTF and BPF_SNPRINTF macros elsewhere in the file - it allows use of bpf_trace_vprintk without manual conversion of varargs to u64 array. Like the bpf_printk macro, bpf_vprintk is meant to be the main interface to the bpf_trace_vprintk helper and thus is uncapitalized. Signed-off-by: Dave Marchevsky --- tools/lib/bpf/bpf_helpers.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tools/lib/bpf/bpf_helpers.h b/tools/lib/bpf/bpf_helpers.h index b9987c3efa3c..43c8115956c3 100644 --- a/tools/lib/bpf/bpf_helpers.h +++ b/tools/lib/bpf/bpf_helpers.h @@ -224,4 +224,22 @@ enum libbpf_tristate { ___param, sizeof(___param)); \ }) +/* + * bpf_vprintk wraps the bpf_trace_printk helper with variadic arguments + * instead of an array of u64. + */ +#define bpf_vprintk(fmt, args...) \ +({ \ + static const char ___fmt[] = fmt; \ + unsigned long long ___param[___bpf_narg(args)]; \ + \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wint-conversion\"") \ + ___bpf_fill(___param, args); \ + _Pragma("GCC diagnostic pop") \ + \ + bpf_trace_vprintk(___fmt, sizeof(___fmt), \ + ___param, sizeof(___param)); \ +}) + #endif