From patchwork Mon Nov 1 06:04:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 12595849 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 EE3B8C433F5 for ; Mon, 1 Nov 2021 06:04:45 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9F23661078 for ; Mon, 1 Nov 2021 06:04:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9F23661078 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 3890280014; Mon, 1 Nov 2021 02:04:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3380980008; Mon, 1 Nov 2021 02:04:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 189C280014; Mon, 1 Nov 2021 02:04:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0220.hostedemail.com [216.40.44.220]) by kanga.kvack.org (Postfix) with ESMTP id 0418E80008 for ; Mon, 1 Nov 2021 02:04:45 -0400 (EDT) Received: from smtpin31.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id B461318020312 for ; Mon, 1 Nov 2021 06:04:44 +0000 (UTC) X-FDA: 78759322488.31.410D844 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) by imf09.hostedemail.com (Postfix) with ESMTP id 62295300010C for ; Mon, 1 Nov 2021 06:04:44 +0000 (UTC) Received: by mail-pg1-f176.google.com with SMTP id x5so6504527pgk.11 for ; Sun, 31 Oct 2021 23:04:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CZbW1Aleg8hcQ6oriKfCOVzwEMQjjmsZLoOFChfxiOE=; b=hLIVcr6CSGMn7q+duUxCWW0eGrpmQBAmB6Wq4FCLbLyQvr2Upd8TZDDWhXwETwIru5 gVsFVTteDomWNPaucmxRqkCCuS8WRWbKXTXFS4O738YFeGYfE7jLWgBhWcP5Wyl3Ixx1 e9YODtfNTOnD4iIYhMk9WCAiID1UqwO6uuIqcXKNmu7EhFjFVJ/VFfeT8r6Dr1npBbY7 zyuY/z7kwCaKGMOzNmsXif+LtjafxWuoctWRkorVboIJqLwC2HTMPIEGJO5cyPXEJAeh sgohILu4rfKSjNpvEjhK4xvo6H+wsmaaOY6Ipo4srFpfRbzLHJNYJVKU90aLM7DlOEJ/ 4Qrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CZbW1Aleg8hcQ6oriKfCOVzwEMQjjmsZLoOFChfxiOE=; b=bf7XY5LMDGaS4kUFAGqvlutrmZQ2SpZ6lhULa3PC542KPV0JaYQxZTkldRRy4c/397 vVgSeTxzlj3WAu0PQ0ph7jZambc5H4YDYVPCzvOzqQa2xLb8+RML7adGyimUPrGIk8m8 +a5NPOOU0pNrxbLf5UV2UoAYDqLmlDKPyOXcdjtMzkCX036pWDx0ja6NbZO6g2NUOwv4 IDTqiW0WXjRA5PFtFvSaiKthFkWqGd478OeGAyxJT4VK+xnUk2tUiRFZ80XnxPbGKQaL HLldFPH/WBSsSHM7IuxDMIisIOsIzFyrqoQ+5/qUazqiygRj2G89H4+mK3FOghHfMPDT SEIg== X-Gm-Message-State: AOAM533a5G1r3nhLuOElqfJ4QBhOE3ACEEDxWqtQz2KFXuUQkaC8HPxX A/0xpuSfB7EjO3MnlRR0B+E= X-Google-Smtp-Source: ABdhPJy5ahFUxXTC3lwrjdq2rffkJFK0bqTnEW/fg2sOG/fpUs8BcRn22EW5Z/8v2ha5HNBZ374p9Q== X-Received: by 2002:a62:e510:0:b0:44c:e06e:80dd with SMTP id n16-20020a62e510000000b0044ce06e80ddmr27033507pff.48.1635746683498; Sun, 31 Oct 2021 23:04:43 -0700 (PDT) Received: from localhost.localdomain ([144.202.123.152]) by smtp.gmail.com with ESMTPSA id g8sm3277586pfc.65.2021.10.31.23.04.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Oct 2021 23:04:43 -0700 (PDT) From: Yafang Shao To: akpm@linux-foundation.org, keescook@chromium.org, rostedt@goodmis.org, mathieu.desnoyers@efficios.com, arnaldo.melo@gmail.com, pmladek@suse.com, peterz@infradead.org, viro@zeniv.linux.org.uk, valentin.schneider@arm.com, qiang.zhang@windriver.com, robdclark@chromium.org, christian@brauner.io, dietmar.eggemann@arm.com, mingo@redhat.com, juri.lelli@redhat.com, vincent.guittot@linaro.org, davem@davemloft.net, kuba@kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, john.fastabend@gmail.com, kpsingh@kernel.org, dennis.dalessandro@cornelisnetworks.com, mike.marciniszyn@cornelisnetworks.com, dledford@redhat.com, jgg@ziepe.ca Cc: linux-rdma@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, oliver.sang@intel.com, lkp@intel.com, Yafang Shao , Alexei Starovoitov , Andrii Nakryiko Subject: [PATCH v7 06/11] samples/bpf/test_overhead_kprobe_kern: make it adopt to task comm size change Date: Mon, 1 Nov 2021 06:04:14 +0000 Message-Id: <20211101060419.4682-7-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211101060419.4682-1-laoar.shao@gmail.com> References: <20211101060419.4682-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 62295300010C X-Stat-Signature: 1ugw6a43cnknt847nnzedc8cju6jurao Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=hLIVcr6C; spf=pass (imf09.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.215.176 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1635746684-346473 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: bpf_probe_read_kernel_str() will add a nul terminator to the dst, then we don't care about if the dst size is big enough. This patch also replaces the hard-coded 16 with TASK_COMM_LEN to make it adopt to task comm size change. Signed-off-by: Yafang Shao Reviewed-by: Kees Cook Cc: Mathieu Desnoyers Cc: Arnaldo Carvalho de Melo Cc: Alexei Starovoitov Cc: Andrii Nakryiko Cc: Peter Zijlstra Cc: Steven Rostedt Cc: Al Viro Cc: Kees Cook Cc: Petr Mladek --- samples/bpf/offwaketime_kern.c | 4 ++-- samples/bpf/test_overhead_kprobe_kern.c | 11 ++++++----- samples/bpf/test_overhead_tp_kern.c | 5 +++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/samples/bpf/offwaketime_kern.c b/samples/bpf/offwaketime_kern.c index 4866afd054da..eb4d94742e6b 100644 --- a/samples/bpf/offwaketime_kern.c +++ b/samples/bpf/offwaketime_kern.c @@ -113,11 +113,11 @@ static inline int update_counts(void *ctx, u32 pid, u64 delta) /* 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/samples/bpf/test_overhead_kprobe_kern.c b/samples/bpf/test_overhead_kprobe_kern.c index f6d593e47037..8fdd2c9c56b2 100644 --- a/samples/bpf/test_overhead_kprobe_kern.c +++ b/samples/bpf/test_overhead_kprobe_kern.c @@ -6,6 +6,7 @@ */ #include #include +#include #include #include #include @@ -22,17 +23,17 @@ int prog(struct pt_regs *ctx) { struct signal_struct *signal; struct task_struct *tsk; - char oldcomm[16] = {}; - char newcomm[16] = {}; + char oldcomm[TASK_COMM_LEN] = {}; + char newcomm[TASK_COMM_LEN] = {}; u16 oom_score_adj; u32 pid; tsk = (void *)PT_REGS_PARM1(ctx); pid = _(tsk->pid); - bpf_probe_read_kernel(oldcomm, sizeof(oldcomm), &tsk->comm); - bpf_probe_read_kernel(newcomm, sizeof(newcomm), - (void *)PT_REGS_PARM2(ctx)); + bpf_probe_read_kernel_str(oldcomm, sizeof(oldcomm), &tsk->comm); + bpf_probe_read_kernel_str(newcomm, sizeof(newcomm), + (void *)PT_REGS_PARM2(ctx)); signal = _(tsk->signal); oom_score_adj = _(signal->oom_score_adj); return 0; diff --git a/samples/bpf/test_overhead_tp_kern.c b/samples/bpf/test_overhead_tp_kern.c index eaa32693f8fc..80edadacb692 100644 --- a/samples/bpf/test_overhead_tp_kern.c +++ b/samples/bpf/test_overhead_tp_kern.c @@ -4,6 +4,7 @@ * modify it under the terms of version 2 of the GNU General Public * License as published by the Free Software Foundation. */ +#include #include #include @@ -11,8 +12,8 @@ struct task_rename { __u64 pad; __u32 pid; - char oldcomm[16]; - char newcomm[16]; + char oldcomm[TASK_COMM_LEN]; + char newcomm[TASK_COMM_LEN]; __u16 oom_score_adj; }; SEC("tracepoint/task/task_rename")