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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 48C14C433F5 for ; Tue, 26 Oct 2021 02:22:22 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C7B4360E74 for ; Tue, 26 Oct 2021 02:22:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C7B4360E74 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 09A72940008; Mon, 25 Oct 2021 22:22:21 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 04B41940007; Mon, 25 Oct 2021 22:22:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E5505940008; Mon, 25 Oct 2021 22:22:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0081.hostedemail.com [216.40.44.81]) by kanga.kvack.org (Postfix) with ESMTP id D5DE8940007 for ; Mon, 25 Oct 2021 22:22:20 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 8CDD48249980 for ; Tue, 26 Oct 2021 02:22:20 +0000 (UTC) X-FDA: 78736989240.17.8C3E953 Received: from mail-il1-f175.google.com (mail-il1-f175.google.com [209.85.166.175]) by imf01.hostedemail.com (Postfix) with ESMTP id 5FDC150882B4 for ; Tue, 26 Oct 2021 02:22:13 +0000 (UTC) Received: by mail-il1-f175.google.com with SMTP id j10so11944678ilu.2 for ; Mon, 25 Oct 2021 19:22:19 -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=aYNLxVJxhJtkV7LDbxh0/fDHQmD9y+lnwZgdD2VF1nY=; b=XgapHKCXLmK3d4ipnGkwLkAGLSdvG7pnijM97IFpuTwDyGAfqY59hcKHAkFeWeODpR Jjw6Crqe3bj2KeTn18MQNqhF6xyIO9m5VCAZSOvjPyxkaMHgxDDOrmQk/awyWCYQDRSk 6bymVQKy2ViFsapdJMYcsCQJtEi8NA++UKtPQznjRMqBWX7HwEOEhQgpCIQYIW4SZyH6 2igGPL3JgSaKMp6J2XuE+q8hBa0Bb5FDYHh3+eJ/bVlPWF67rMGCtmNjs684L/5vq1J0 gMM5AX63+DqOco6YtYfXmMbgeSeiXxzR2KzEe/Lxfp/IWkwi73Le44LxB0368IuSuxbd 0K2Q== 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=aYNLxVJxhJtkV7LDbxh0/fDHQmD9y+lnwZgdD2VF1nY=; b=CDwexOZTQinNiWSSF84GutFQRKEl2k1QCw3W4DOzVbQajCTUCthOzYQiXcZjArlKKK GZzvpMLKvX5IODborgJBFLkUGMSAN+m6fNUWFRn7lIEIhmBqcuI53U2KkHAXl8UjtTD8 3PdLjwWNS5NQivLur/YCDRtmVCVBFtbptBk2fLGajO2IhgXX3mK2QDK5dBx6ohBG+GlB K+NM1f/bUDl/G1I4uWly2y27snuz5Ig3MsN33MuXA4yFh7FVzg89tblxpko+BhNoOIAD lpNKSa8mMqK2ycQ0FcyRtT65Jmf1sqtPCWHABRLI0pW3fIi4h3WtTawUAywxEcvWWMdo O14A== X-Gm-Message-State: AOAM530/lJUIVhgYVWMjx02chs/OTMbp6k48nsRv9IAfwOT/UAxZRiiQ 5UiX5wDI8FAXrgzp6dyLAAjGnsXwQ0znqhI7DMA= X-Google-Smtp-Source: ABdhPJy1/BIRcRVvc7L15TX90MIkD80tatO8voO6JJbloERLJG1VNNMnwLh8i+0LovAq3pIM8zOUowRpitmZp3NbmsQ= X-Received: by 2002:a05:6e02:218f:: with SMTP id j15mr12615063ila.23.1635214939600; Mon, 25 Oct 2021 19:22:19 -0700 (PDT) MIME-Version: 1.0 References: <20211025083315.4752-1-laoar.shao@gmail.com> <20211025083315.4752-11-laoar.shao@gmail.com> <202110251428.B891AD6ACB@keescook> In-Reply-To: <202110251428.B891AD6ACB@keescook> From: Yafang Shao Date: Tue, 26 Oct 2021 10:21:43 +0800 Message-ID: Subject: Re: [PATCH v6 10/12] tools/testing/selftests/bpf: make it adopt to task comm size change To: Kees Cook Cc: Andrew Morton , Steven Rostedt , Mathieu Desnoyers , Arnaldo Carvalho de Melo , Petr Mladek , Peter Zijlstra , Al Viro , Valentin Schneider , Qiang Zhang , robdclark , christian , Dietmar Eggemann , Ingo Molnar , Juri Lelli , Vincent Guittot , David Miller , Jakub Kicinski , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin Lau , Song Liu , Yonghong Song , john fastabend , KP Singh , dennis.dalessandro@cornelisnetworks.com, mike.marciniszyn@cornelisnetworks.com, dledford@redhat.com, jgg@ziepe.ca, linux-rdma@vger.kernel.org, netdev , bpf , "linux-perf-use." , linux-fsdevel@vger.kernel.org, Linux MM , LKML , kernel test robot , kbuild test robot , Andrii Nakryiko Content-Type: text/plain; charset="UTF-8" X-Stat-Signature: 3wt9gredhjxn11be6sdyc4xft3n3i5ex X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 5FDC150882B4 Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=XgapHKCX; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf01.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.166.175 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com X-HE-Tag: 1635214933-986191 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Tue, Oct 26, 2021 at 5:29 AM Kees Cook wrote: > > On Mon, Oct 25, 2021 at 08:33:13AM +0000, 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. > > > > In these BPF programs, one thing to be improved is the > > sched:sched_switch tracepoint args. As the tracepoint args are derived > > from the kernel, we'd better make it same with the kernel. So the macro > > TASK_COMM_LEN is converted to type enum, then all the BPF programs can > > get it through BTF. > > > > Signed-off-by: Yafang Shao > > Cc: Mathieu Desnoyers > > Cc: Arnaldo Carvalho de Melo > > Cc: Andrii Nakryiko > > Cc: Peter Zijlstra > > Cc: Steven Rostedt > > Cc: Al Viro > > Cc: Kees Cook > > Cc: Petr Mladek > > --- > > include/linux/sched.h | 9 +++++++-- > > tools/testing/selftests/bpf/progs/test_stacktrace_map.c | 6 +++--- > > tools/testing/selftests/bpf/progs/test_tracepoint.c | 6 +++--- > > 3 files changed, 13 insertions(+), 8 deletions(-) > > > > diff --git a/include/linux/sched.h b/include/linux/sched.h > > index c1a927ddec64..124538db792c 100644 > > --- a/include/linux/sched.h > > +++ b/include/linux/sched.h > > @@ -274,8 +274,13 @@ struct task_group; > > > > #define get_current_state() READ_ONCE(current->__state) > > > > -/* Task command name length: */ > > -#define TASK_COMM_LEN 16 > > +/* > > + * Define the task command name length as enum, then it can be visible to > > + * BPF programs. > > + */ > > +enum { > > + TASK_COMM_LEN = 16, > > +}; > > > > extern void scheduler_tick(void); > > > > diff --git a/tools/testing/selftests/bpf/progs/test_stacktrace_map.c b/tools/testing/selftests/bpf/progs/test_stacktrace_map.c > > index 00ed48672620..e9b602a6dc1b 100644 > > --- a/tools/testing/selftests/bpf/progs/test_stacktrace_map.c > > +++ b/tools/testing/selftests/bpf/progs/test_stacktrace_map.c > > @@ -1,7 +1,7 @@ > > // SPDX-License-Identifier: GPL-2.0 > > // Copyright (c) 2018 Facebook > > > > -#include > > +#include > > Why is this change needed here and below? > If the BPF programs want to use the type defined in the kernel, for example the enum we used here, we must include the vmlinux.h generated by BTF. > > #include > > > > #ifndef PERF_MAX_STACK_DEPTH > > @@ -41,11 +41,11 @@ struct { > > /* taken from /sys/kernel/debug/tracing/events/sched/sched_switch/format */ > > struct sched_switch_args { > > unsigned long long pad; > > - char prev_comm[16]; > > + char prev_comm[TASK_COMM_LEN]; > > int prev_pid; > > int prev_prio; > > long long prev_state; > > - char next_comm[16]; > > + char next_comm[TASK_COMM_LEN]; > > int next_pid; > > int next_prio; > > }; > > diff --git a/tools/testing/selftests/bpf/progs/test_tracepoint.c b/tools/testing/selftests/bpf/progs/test_tracepoint.c > > index 4b825ee122cf..f21982681e28 100644 > > --- a/tools/testing/selftests/bpf/progs/test_tracepoint.c > > +++ b/tools/testing/selftests/bpf/progs/test_tracepoint.c > > @@ -1,17 +1,17 @@ > > // SPDX-License-Identifier: GPL-2.0 > > // Copyright (c) 2017 Facebook > > > > -#include > > +#include > > #include > > > > /* taken from /sys/kernel/debug/tracing/events/sched/sched_switch/format */ > > struct sched_switch_args { > > unsigned long long pad; > > - char prev_comm[16]; > > + char prev_comm[TASK_COMM_LEN]; > > int prev_pid; > > int prev_prio; > > long long prev_state; > > - char next_comm[16]; > > + char next_comm[TASK_COMM_LEN]; > > int next_pid; > > int next_prio; > > }; > > -- > > 2.17.1 > > > > -- > Kees Cook -- Thanks Yafang