From patchwork Mon Oct 25 08:33:09 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yafang Shao X-Patchwork-Id: 12581039 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 DEA3BC433F5 for ; Mon, 25 Oct 2021 08:33:58 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 93ED5604AC for ; Mon, 25 Oct 2021 08:33:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 93ED5604AC 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 3C8C994000A; Mon, 25 Oct 2021 04:33:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3515C940007; Mon, 25 Oct 2021 04:33:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 21F9694000A; Mon, 25 Oct 2021 04:33:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0237.hostedemail.com [216.40.44.237]) by kanga.kvack.org (Postfix) with ESMTP id 10B66940007 for ; Mon, 25 Oct 2021 04:33:58 -0400 (EDT) Received: from smtpin38.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id C024A2BA8E for ; Mon, 25 Oct 2021 08:33:57 +0000 (UTC) X-FDA: 78734296914.38.DB7738A Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by imf29.hostedemail.com (Postfix) with ESMTP id 6D5139000163 for ; Mon, 25 Oct 2021 08:33:57 +0000 (UTC) Received: by mail-pf1-f175.google.com with SMTP id l203so5328449pfd.2 for ; Mon, 25 Oct 2021 01:33:57 -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=0MARTQhRayCcJOXrt50qrZSWHcrTOqEBviMLv+qW86Q=; b=XP9d6g5akaizE8xXosLToU+YDFW2+ji6UQwvG9rY0KePWcCtYWku40Pftn6MNFy6ip vn2fAFRhM2XEAKVYSUOXMorB9/KfaXT5tIoXXEQO4+QGgcoJMtoUh1GL6ACnYpUx6+3C QWv23PsERcEm/e+kNkJeknBljJ82nng5FtIei5wWu5KnnZsjLSmcD0c/G7mOTvMYxc7r FDpVDKE+aQraRJ2VZ/WII3FFKGCj75F4Se9RsMn23gkqa7b8qz8f+bE8VohWIdLZDA8L r77tFIHw52606BnHROajGx+deZ42CI20qBGSU6LCXqjGc1MuIlzzx5bY9H37DUsYIIvm cgIQ== 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=0MARTQhRayCcJOXrt50qrZSWHcrTOqEBviMLv+qW86Q=; b=H4pDL2V8v8UCViGlK7/k79m32mprL7XITtvbxlr+cDECunJXkof5hPVfbLn/0rBmuY vKZdFEg55uPK042EQMcrEpc7u6ki0k5iQ/X9q0Ksh919PQ9WkUtI1xVEcClX1WhLVoFd WRPSCpq50K5ouDZj01YUYmHV0lPbfWZEjQWRTbv14ZgdunviI1fdo0e32yIoy4F0CuE2 RDSykgEzYmZbgFSzwad7HYCh+yfpE9e/nSoXeBJS3AXigTDW2Ik2spp2RwxdoLNrvL0I ERobe31FC3x2M0/HnjTQVxkIcMaqUBDgaBnWdBgBmzBecxZA9DMuLyMHhxW3/lgMob74 FjSg== X-Gm-Message-State: AOAM533uyGcx7lzY7UAj6XU5iV5Fwdygr8/rzU5QjiN++iKHO91driKQ poZizIRDeVp92CX+qN+UG8w= X-Google-Smtp-Source: ABdhPJw+MS/fFYKdGRF6+qFNhT0P9QZUUEFfE9dLlDbmgJIuvaqC53bEnXgTwCqGCnrhahx5AU6oUw== X-Received: by 2002:a63:7504:: with SMTP id q4mr12363197pgc.103.1635150836561; Mon, 25 Oct 2021 01:33:56 -0700 (PDT) Received: from localhost.localdomain ([140.82.17.67]) by smtp.gmail.com with ESMTPSA id p13sm2495694pfo.102.2021.10.25.01.33.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Oct 2021 01:33:56 -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 , Andrii Nakryiko Subject: [PATCH v6 06/12] samples/bpf/test_overhead_kprobe_kern: make it adopt to task comm size change Date: Mon, 25 Oct 2021 08:33:09 +0000 Message-Id: <20211025083315.4752-7-laoar.shao@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20211025083315.4752-1-laoar.shao@gmail.com> References: <20211025083315.4752-1-laoar.shao@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 6D5139000163 Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=XP9d6g5a; spf=pass (imf29.hostedemail.com: domain of laoar.shao@gmail.com designates 209.85.210.175 as permitted sender) smtp.mailfrom=laoar.shao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: xaezqrj4k7waz5itmzi3h5t1f3akigtp X-Rspamd-Server: rspam06 X-HE-Tag: 1635150837-675173 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 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 Reviewed-by: Kees Cook --- samples/bpf/test_overhead_kprobe_kern.c | 11 ++++++----- samples/bpf/test_overhead_tp_kern.c | 5 +++-- 2 files changed, 9 insertions(+), 7 deletions(-) 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")