Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1405530pxb; Thu, 21 Oct 2021 23:40:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxabg5Ndmc16lXTNM5C/TlglXiZ96qGxNimYioOmKMvTU5z+EIiItc1iPxvoXnoRQP5K4xH X-Received: by 2002:a05:6402:190f:: with SMTP id e15mr14955771edz.310.1634884848095; Thu, 21 Oct 2021 23:40:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634884848; cv=none; d=google.com; s=arc-20160816; b=xQFqd1TeaqKfD8dEHKr+SZTVNcieQDXLodBR5/I2Epsf2wI8N8dQtrdtFlktzA8tSg gFOFGH3kLHTHfgf59r5t/r7Uy2LC3VGTuh5E47hO5aMz4t7thhasKC56EpVX1LPbZ42B Jz/WPAF5xWrD4LYZY/nmViaA843GjjRfvirgcwO11+411K9PzgnOa5V+q8BHueBWYGJN AUobG+VMCQyExqUqvw7XZ/s+g9L6Ck6Rlkmj8V4DQbZOiQ6wM9jxabjZ4mUfVluSWPmY cB7ZQLg/nG/mV60xK5d205sPclt2hOnIJ2sedF/ug7Uk6FFYivWD62xTY3WVGmCmpujA co2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=c/GFWfrfQCEwAUkTRHGoboE0d5lC1Uh+koDzmicEca0=; b=1KvvKI96S316ye3T0busGtsCcDdlZkCUn4A2WAvzNjtNgTg4gTyQLOmreoPMwaX6fA X7vrgg2nj4PjLeYj5V3gH83BxiSVk3ZtdABkhk3vjuX1UZHvaNivx2xSHBtgtzVtLLEQ cIObK9y0gV/xvIBn3bj+pc9ZXrOBKOuJBdQYqe26pJHdMh4gFRRA4Y0UUhhQkh3bBIv5 5YWH3/UgnkwGL6VppGehecxxEtAPKZY8RhyHL/WzjdNDfeVu7aFKUCd3JlyV1t3WPkiW EXmakkReGkX3yELqauSP1Z8HjEFMxITRcy/3xS169mgaQqJn7ZG7RcsEIMW6fEEGhzK6 RsvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=WMbENLpz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m23si9359059edj.208.2021.10.21.23.40.22; Thu, 21 Oct 2021 23:40:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=WMbENLpz; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231942AbhJVGi6 (ORCPT + 99 others); Fri, 22 Oct 2021 02:38:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232060AbhJVGix (ORCPT ); Fri, 22 Oct 2021 02:38:53 -0400 Received: from mail-io1-xd34.google.com (mail-io1-xd34.google.com [IPv6:2607:f8b0:4864:20::d34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C743C061766; Thu, 21 Oct 2021 23:36:36 -0700 (PDT) Received: by mail-io1-xd34.google.com with SMTP id o184so4018496iof.6; Thu, 21 Oct 2021 23:36:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=c/GFWfrfQCEwAUkTRHGoboE0d5lC1Uh+koDzmicEca0=; b=WMbENLpzZjcQwzZGiPW9Rhj/vFgwtV2c/zTneotJXvWjk7VUNpF5RqaRXkH7XVbb1v m/Bt+TPNkNMeG6CjLyjFtqDGplI7JGUtLGfH1tHhdqQauWPvrpXwMZhv+FT8usoTTzA4 7yQ8eYL40BoICYMya8ERyMssfiR9dSuRYuHP44OoJ3KGgq8N/cMF43J7WJZvQvaBLEYC WC5lVPCnSPrD4rMtJ2E2YXIQRuoiX/lZtPhoz6BwAWzPDoJe962/hNugrkTW1efe9lYR rEfL1Ylxd1IQCgi6FL1FOj/9mOj5+dxGwhbrXYgVM8dJfJnARoVGkPhGsTWCUTR+WZph orSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=c/GFWfrfQCEwAUkTRHGoboE0d5lC1Uh+koDzmicEca0=; b=H0aW4brsariRoaYr2AmT/m5WuvpddmvwHJn1ZEPAsIBrwTk/d6LYk6iExoAz3A4/n4 vgNEU2nnpubUahd65a9GCJX9GG8Do8l8Tbu34OKu/QsyKEkjMU96p4TZc7d9iKz86Wrv fh2N8INqJWNavwjKviqo8/FcFyVbApRWu1x1nz2Ww5eeeseE+pxFldsTonOVjumIWEBS uquOpZpRXYUClwftPSPK0WUidfogZnQ9d1z8N3IuJv1R1tbW9E+TbBjEC1IZB0EdUANA rsMhHJToz5l7tsmSu85RmTXPXDQp+RFz4ywv+zGAOFycm7YbuEweaKpw3RCF80iX4b80 qZvQ== X-Gm-Message-State: AOAM532BXbEh6dujVoZvsV/H1qV8eVew2Y8p1v3NpiUfIioZRqw5ku8N VeN5hweICZoNZqZPIrioYWB/DPD3GzxLBYI5qCA= X-Received: by 2002:a05:6638:1607:: with SMTP id x7mr6984970jas.128.1634884595972; Thu, 21 Oct 2021 23:36:35 -0700 (PDT) MIME-Version: 1.0 References: <20211021034603.4458-1-laoar.shao@gmail.com> <20211021034603.4458-4-laoar.shao@gmail.com> In-Reply-To: From: Yafang Shao Date: Fri, 22 Oct 2021 14:36:00 +0800 Message-ID: Subject: Re: [PATCH v5 13/15] tools/testing/selftests/bpf: use TASK_COMM_LEN_16 instead of hard-coded 16 To: Andrii Nakryiko Cc: Kees Cook , Steven Rostedt , Mathieu Desnoyers , Arnaldo Carvalho de Melo , Petr Mladek , Peter Ziljstra , Al Viro , Andrew Morton , Valentin Schneider , Qiang Zhang , robdclark , Christian Brauner , Dietmar Eggemann , Ingo Molnar , Juri Lelli , Vincent Guittot , "David S. Miller" , Jakub Kicinski , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin Lau , Song Liu , Yonghong Song , john fastabend , KP Singh , Networking , bpf , "linux-perf-use." , linux-fsdevel@vger.kernel.org, open list , kernel test robot , kbuild test robot Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Oct 22, 2021 at 6:44 AM Andrii Nakryiko wrote: > > On Wed, Oct 20, 2021 at 8:46 PM Yafang Shao wrote: > > > > The hard-coded 16 is used in various bpf progs. These progs get task > > comm either via bpf_get_current_comm() or prctl() or > > bpf_core_read_str(), all of which can work well even if the task comm size > > is changed. > > Below is the detailed information, > > > > bpf_get_current_comm: > > progs/test_ringbuf.c > > progs/test_ringbuf_multi.c > > > > prctl: > > prog_tests/test_overhead.c > > prog_tests/trampoline_count.c > > > > bpf_core_read_str: > > progs/test_core_reloc_kernel.c > > progs/test_sk_storage_tracing.c > > > > We'd better replace the hard-coded 16 with TASK_COMM_LEN_16 to make it > > more grepable. > > > > Signed-off-by: Yafang Shao > > Cc: Mathieu Desnoyers > > Cc: Arnaldo Carvalho de Melo > > Cc: Peter Zijlstra > > Cc: Steven Rostedt > > Cc: Kees Cook > > Cc: Al Viro > > Cc: Petr Mladek > > --- > > tools/testing/selftests/bpf/Makefile | 2 +- > > tools/testing/selftests/bpf/prog_tests/ringbuf.c | 3 ++- > > tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c | 3 ++- > > .../testing/selftests/bpf/prog_tests/sk_storage_tracing.c | 3 ++- > > tools/testing/selftests/bpf/prog_tests/test_overhead.c | 3 ++- > > tools/testing/selftests/bpf/prog_tests/trampoline_count.c | 3 ++- > > tools/testing/selftests/bpf/progs/profiler.h | 7 ++++--- > > tools/testing/selftests/bpf/progs/profiler.inc.h | 8 ++++---- > > tools/testing/selftests/bpf/progs/pyperf.h | 4 ++-- > > tools/testing/selftests/bpf/progs/strobemeta.h | 6 +++--- > > .../testing/selftests/bpf/progs/test_core_reloc_kernel.c | 3 ++- > > tools/testing/selftests/bpf/progs/test_ringbuf.c | 3 ++- > > tools/testing/selftests/bpf/progs/test_ringbuf_multi.c | 3 ++- > > .../testing/selftests/bpf/progs/test_sk_storage_tracing.c | 5 +++-- > > tools/testing/selftests/bpf/progs/test_skb_helpers.c | 5 ++--- > > tools/testing/selftests/bpf/progs/test_stacktrace_map.c | 5 +++-- > > tools/testing/selftests/bpf/progs/test_tracepoint.c | 5 +++-- > > 17 files changed, 41 insertions(+), 30 deletions(-) > > > > diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile > > index 799b88152e9e..5e72d783d3fe 100644 > > --- a/tools/testing/selftests/bpf/Makefile > > +++ b/tools/testing/selftests/bpf/Makefile > > @@ -279,7 +279,7 @@ MENDIAN=$(if $(IS_LITTLE_ENDIAN),-mlittle-endian,-mbig-endian) > > > > CLANG_SYS_INCLUDES = $(call get_sys_includes,$(CLANG)) > > BPF_CFLAGS = -g -D__TARGET_ARCH_$(SRCARCH) $(MENDIAN) \ > > - -I$(INCLUDE_DIR) -I$(CURDIR) -I$(APIDIR) \ > > + -I$(INCLUDE_DIR) -I$(CURDIR) -I$(APIDIR) -I${TOOLSINCDIR} \ > > please don't add new include paths unnecessarily. See my comment on > another patch, if you add those new constants as enums, they will be > automatically available in vmlinux BTF and thus in auto-generated > vmlinux.h header (for those programs using it). Yes, after converting it to enum, the BPF programs can get it from the generated vmlinux.h. > For others, I'd just > leave hard-coded 16 or re-defined TASK_COMM_LEN_16 where appropriate. > It seems not all the BPF programs can include the vmlinux.h. What we really care about here is the copy of task comm should be with a nul terminator, if we can assure it, then the size used by the BPF is not important. I have checked the copy of task comm in all these BPF programs one by one, and replaced the unsafe bpf_probe_read_kernel() with bpf_probe_read_kernel_str(), after that change, I think we can leave hard-coded 16 for the progs which can't include vmlinux.h. > > -I$(abspath $(OUTPUT)/../usr/include) > > > > CLANG_CFLAGS = $(CLANG_SYS_INCLUDES) \ > > diff --git a/tools/testing/selftests/bpf/prog_tests/ringbuf.c b/tools/testing/selftests/bpf/prog_tests/ringbuf.c > > index 4706cee84360..ac82d57c09dc 100644 > > --- a/tools/testing/selftests/bpf/prog_tests/ringbuf.c > > +++ b/tools/testing/selftests/bpf/prog_tests/ringbuf.c > > @@ -12,6 +12,7 @@ > > #include > > #include > > #include > > +#include > > #include "test_ringbuf.lskel.h" > > > > #define EDONE 7777 > > @@ -22,7 +23,7 @@ struct sample { > > int pid; > > int seq; > > long value; > > - char comm[16]; > > + char comm[TASK_COMM_LEN_16]; > > how much value is in this "grep-ability", really? I'm not convinced > all this code churn is justified. > > > }; > > > > static int sample_cnt; > > diff --git a/tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c b/tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c > > index 167cd8a2edfd..f0748305ffd6 100644 > > --- a/tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c > > +++ b/tools/testing/selftests/bpf/prog_tests/ringbuf_multi.c > > @@ -2,6 +2,7 @@ > > #define _GNU_SOURCE > > #include > > #include > > +#include > > #include "test_ringbuf_multi.skel.h" > > > > static int duration = 0; > > [...] -- Thanks Yafang