From patchwork Sat Aug 28 05:19:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dave Marchevsky X-Patchwork-Id: 12463259 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_PATCH,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SPF_HELO_NONE,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 7A547C432BE for ; Sat, 28 Aug 2021 05:20:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4F63E60ED3 for ; Sat, 28 Aug 2021 05:20:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231522AbhH1FVI (ORCPT ); Sat, 28 Aug 2021 01:21:08 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:13868 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229555AbhH1FVH (ORCPT ); Sat, 28 Aug 2021 01:21:07 -0400 Received: from pps.filterd (m0109334.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 17S5EKF8029770 for ; Fri, 27 Aug 2021 22:20:16 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : content-type : content-transfer-encoding : mime-version; s=facebook; bh=4zvGpW/+CcRKYQ0ujJoY+jtdQUnrFfYZk0drmY+X7J4=; b=UPJWw77zQ+R6itueR2VEG6DS16O4SXrg7opB5oWxyok7YhVTg3/LS7Wa1/vHo9zZTpMK i0ORW0yTQUiEPrKwv8CrbtRi4v8H+Tu11Yc7+pYCkGAI5YGYd6YV/l6IEXDnpVSVyqXF Jvjkq9Ed5cFeESgr8lcCSvhIG0hsgcjcX9E= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com with ESMTP id 3aq70jt4cu-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Fri, 27 Aug 2021 22:20:15 -0700 Received: from intmgw002.25.frc3.facebook.com (2620:10d:c085:208::11) by mail.thefacebook.com (2620:10d:c085:11d::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Fri, 27 Aug 2021 22:20:15 -0700 Received: by devbig030.frc3.facebook.com (Postfix, from userid 158236) id D00AF5BF0DF1; Fri, 27 Aug 2021 22:20:10 -0700 (PDT) From: Dave Marchevsky To: CC: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Yonghong Song , , Dave Marchevsky Subject: [PATCH v3 bpf-next 0/7] bpf: implement variadic printk helper Date: Fri, 27 Aug 2021 22:19:59 -0700 Message-ID: <20210828052006.1313788-1-davemarchevsky@fb.com> X-Mailer: git-send-email 2.30.2 X-FB-Internal: Safe X-FB-Source: Intern X-Proofpoint-ORIG-GUID: fl5Lq00a-7Z3EJUx8BNcWxvmplUUzAub X-Proofpoint-GUID: fl5Lq00a-7Z3EJUx8BNcWxvmplUUzAub X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-08-28_01:2021-08-27,2021-08-28 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 lowpriorityscore=0 malwarescore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 spamscore=0 adultscore=0 phishscore=0 bulkscore=0 impostorscore=0 priorityscore=1501 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108280031 X-FB-Internal: deliver Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net This series introduces a new helper, bpf_trace_vprintk, which functions like bpf_trace_printk but supports > 3 arguments via a pseudo-vararg u64 array. The bpf_printk libbpf convenience macro is modified to use bpf_trace_vprintk when > 3 varargs are passed, otherwise the previous behavior - using bpf_trace_printk - is retained. Helper functions and macros added during the implementation of bpf_seq_printf and bpf_snprintf do most of the heavy lifting for bpf_trace_vprintk. There's no novel format string wrangling here. Usecase here is straightforward: Giving BPF program writers a more powerful printk will ease development of BPF programs, particularly during debugging and testing, where printk tends to be used. This feature was proposed by Andrii in libbpf mirror's issue tracker [1]. [1] https://github.com/libbpf/libbpf/issues/315 v2 -> v3: * Clean up patch 3's commit message [Alexei] * Add patch 4, which modifies __bpf_printk to use 'static const char' to store fmt string with fallback for older kernels [Andrii] * rebase v1 -> v2: * Naming conversation seems to have gone in favor of keeping bpf_trace_vprintk, names are unchanged * Patch 3 now modifies bpf_printk convenience macro to choose between __bpf_printk and __bpf_vprintk 'implementation' macros based on arg count. __bpf_vprintk is a renaming of bpf_vprintk convenience macro from v1, __bpf_printk is the existing bpf_printk implementation. This patch could use some scrutiny as I think current implementation may regress developer experience in a specific case, turning a compile-time error into a load-time error. Unclear to me how common the case is, or whether the macro magic I chose is ideal. * char ___fmt[] to static const char ___fmt[] change was not done, wanted to leave __bpf_printk 'implementation' macro unchanged for v2 to ease discussion of above point * Removed __always_inline from __set_printk_clr_event [Andrii] * Simplified bpf_trace_printk docstring to refer to other functions instead of copy/pasting and avoid specifying 12 vararg limit [Andrii] * Migrated trace_printk selftest to use ASSERT_ instead of CHECK * Adds new patch 5, previous patch 5 is now 6 * Migrated trace_vprintk selftest to use ASSERT_ instead of CHECK, open_and_load instead of separate open, load [Andrii] * Patch 2's commit message now correctly mentions trace_pipe instead of dmesg [Andrii] Dave Marchevsky (7): bpf: merge printk and seq_printf VARARG max macros bpf: add bpf_trace_vprintk helper libbpf: Modify bpf_printk to choose helper based on arg count libbpf: use static const fmt string in __bpf_printk bpftool: only probe trace_vprintk feature in 'full' mode selftests/bpf: Migrate prog_tests/trace_printk CHECKs to ASSERTs selftests/bpf: add trace_vprintk test prog include/linux/bpf.h | 3 + include/uapi/linux/bpf.h | 9 +++ kernel/bpf/core.c | 5 ++ kernel/bpf/helpers.c | 6 +- kernel/trace/bpf_trace.c | 54 ++++++++++++++- tools/bpf/bpftool/feature.c | 1 + tools/include/uapi/linux/bpf.h | 9 +++ tools/lib/bpf/bpf_helpers.h | 51 ++++++++++++--- tools/testing/selftests/bpf/Makefile | 3 +- .../selftests/bpf/prog_tests/trace_printk.c | 24 +++---- .../selftests/bpf/prog_tests/trace_vprintk.c | 65 +++++++++++++++++++ .../selftests/bpf/progs/trace_vprintk.c | 25 +++++++ tools/testing/selftests/bpf/test_bpftool.py | 22 +++---- 13 files changed, 234 insertions(+), 43 deletions(-) create mode 100644 tools/testing/selftests/bpf/prog_tests/trace_vprintk.c create mode 100644 tools/testing/selftests/bpf/progs/trace_vprintk.c