Message ID | 20230922234444.3115821-1-namhyung@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:910f:0:b0:403:3b70:6f57 with SMTP id r15csp9205vqg; Fri, 22 Sep 2023 17:45:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEw0tsmk0zjwhRteC/PyfwWZiU7/S+815F5eKIF1nNUN1FmfBYpAiOshLY0fbIzCsLCak1+ X-Received: by 2002:a17:90a:be03:b0:26d:2d77:da7b with SMTP id a3-20020a17090abe0300b0026d2d77da7bmr1135856pjs.6.1695429922022; Fri, 22 Sep 2023 17:45:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695429922; cv=none; d=google.com; s=arc-20160816; b=wif5q9CbsKGFHADSMj0itUUCOM8sdaeyBaYYqIZzfbjcm8yH/Xsm3PkTE9+kGQfQax qXkqo5J7Naelyhj9o6BMuWtlc0QH4WKrX5gwML6upx066PD6/9t3rxlH9O5BTgZhSHA8 wR2gxtcsvOOxZoWTkXQKdTgUZB2jku3lrRDCYwOdmB4EknwWuGylUTUvi6NO2EC+o7pP i3ARrdpvmmXxu2c2PSM675GNx52uQvt5QMZmogSaT2/GjATYr6vpHXES70ui/IGDcghn 496SY3PBp6y3rK+sUyTgcTIIq2YNcCHsyIvYnq7Ty6gCFsg7+cFK1R7MUokLJ2wddZgE GCfA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:sender:dkim-signature; bh=MZpY1IZ4bUrCy8aga9AziYMkBusuoXKm+AQsy7SMzlw=; fh=Eu3OfQ0ohnhl6u2myNPCo9midvMFa9y2PC9Dj+pizlY=; b=JGY5FWgaAmoa2C5DXy1hN9WiWJPbdbtegbDt8tnFlV6n6lrmwnWjPPvPu9s1iMbdNA x6BO2HJeuOtYEU4pfwek3MRAaDFPnfsJqRWdqGJABHIw48X9lNq6axxxgDH55IGTpr+o fsRi5sYBHg+UAYuSBvipOipRaAsgFo3ByQ0MSC0uc+cFOzdLB46NZxxycT3pWq/9KK+x lx1TAlQIe4E5JJSMhKc4i24wlNBO3HNjAXHr3t7bRgeaGp9DK53B1PqPXlKbuFkwhth/ 5btXu2tTAGBM9RrMKsR/qlE3R66n3ShXaALf/V/XqgJLuTQeim03DHJ4L28GRobt1q5Z OQmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=I7qHZ9FG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id ct14-20020a17090af58e00b0026f3e1e9639si7212895pjb.40.2023.09.22.17.45.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 17:45:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=I7qHZ9FG; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by pete.vger.email (Postfix) with ESMTP id B76A183BD994; Fri, 22 Sep 2023 16:47:15 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230274AbjIVXoy (ORCPT <rfc822;pwkd43@gmail.com> + 28 others); Fri, 22 Sep 2023 19:44:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229628AbjIVXoy (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 22 Sep 2023 19:44:54 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 345DE1A2; Fri, 22 Sep 2023 16:44:48 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1c328b53aeaso27243215ad.2; Fri, 22 Sep 2023 16:44:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695426287; x=1696031087; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:from:to:cc:subject:date:message-id:reply-to; bh=MZpY1IZ4bUrCy8aga9AziYMkBusuoXKm+AQsy7SMzlw=; b=I7qHZ9FGWnL1tI9P5bkbztyAZgioK+j4J0gCHGbOsoaH+8+JD0ZE1fRwRbKZVoWHSx +jjoDB42lb/HZHYQk4WZu+FsCWpV9itrI/UeyMtpsQKCSCOQNHu/q/MG2haYr6lHqPib q57qW/x5l8vOw0InM0lD3JZeCm4lsRBD/uelVV/GqDDxdDO74z+18fsoLo16Xs57y5XM 8efU7SDOjXI+nb9khHcC2JpaQLA1cDvcHl4kuXztrYXPTGll/ve5Qjd1WcJ8R/+x8N7U VKp1MPWqbyRMFnnEKyWs2AWBoRYe3HwbjXwD3yYyRI9BAGlXHEEU8R9BHcoxDo2/g0OR wdyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695426287; x=1696031087; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:sender:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=MZpY1IZ4bUrCy8aga9AziYMkBusuoXKm+AQsy7SMzlw=; b=ETSpG2vvgIS12V7H20jnw7Z63xi/SYYP312uWc3EN0CHoK7DUD1lTJQGBCgntUbFQ3 oHoYS4wFZaYChd0I8RMr0eEhxTxaHJER7HfNf3wMs5MU1l/NbGhMy5cPVqXuiKsskbqM dN6uphzzWw/i7A3NfkhIT91xwJWRkPqtimCZEmonvyzQMYnK8Wx+/urisQYMxCifACrw EY1Jx8A7AKYmItXs5tTV4Lwnmtl0xuQWaxVRUfEqI9Cyk/PuDKowg3iJbOx1EiwpNu3q vziyHrzzfTeVQyoigT9C/PLK505//4Sy7l7WGgsmbFAVxkhUEj30HVpOzP+aMwc+C/E4 PJLQ== X-Gm-Message-State: AOJu0Yx+qbIrJpTk5gJGlASL1Og7BXYf3m/ARdLLbBpg4ub4WLs4gstZ pKobyFGG9C+j76Ie9ne6LPY= X-Received: by 2002:a17:902:ab01:b0:1b8:66f6:87a3 with SMTP id ik1-20020a170902ab0100b001b866f687a3mr802257plb.52.1695426287474; Fri, 22 Sep 2023 16:44:47 -0700 (PDT) Received: from bangji.hsd1.ca.comcast.net ([2601:647:6780:42e0:32b8:255a:115:8538]) by smtp.gmail.com with ESMTPSA id l19-20020a170902d35300b001bf5e24b2a8sm4076519plk.174.2023.09.22.16.44.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 16:44:46 -0700 (PDT) Sender: Namhyung Kim <namhyung@gmail.com> From: Namhyung Kim <namhyung@kernel.org> To: Arnaldo Carvalho de Melo <acme@kernel.org>, Jiri Olsa <jolsa@kernel.org> Cc: Ian Rogers <irogers@google.com>, Adrian Hunter <adrian.hunter@intel.com>, Peter Zijlstra <peterz@infradead.org>, Ingo Molnar <mingo@kernel.org>, LKML <linux-kernel@vger.kernel.org>, linux-perf-users@vger.kernel.org, Song Liu <song@kernel.org>, Hao Luo <haoluo@google.com>, bpf@vger.kernel.org Subject: [PATCH] perf record: Fix BTF type checks in the off-cpu profiling Date: Fri, 22 Sep 2023 16:44:44 -0700 Message-ID: <20230922234444.3115821-1-namhyung@kernel.org> X-Mailer: git-send-email 2.42.0.515.g380fc7ccd1-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=2.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Fri, 22 Sep 2023 16:47:15 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777787126064155142 X-GMAIL-MSGID: 1777787126064155142 |
Series |
perf record: Fix BTF type checks in the off-cpu profiling
|
|
Commit Message
Namhyung Kim
Sept. 22, 2023, 11:44 p.m. UTC
The BTF func proto for a tracepoint has one more argument than the
actual tracepoint function since it has a context argument at the
begining. So it should compare to 5 when the tracepoint has 4
arguments.
typedef void (*btf_trace_sched_switch)(void *, bool, struct task_struct *, struct task_struct *, unsigned int);
Also, recent change in the perf tool would use a hand-written minimal
vmlinux.h to generate BTF in the skeleton. So it won't have the info
of the tracepoint. Anyway it should use the kernel's vmlinux BTF to
check the type in the kernel.
Fixes: b36888f71c85 ("perf record: Handle argument change in sched_switch")
Cc: Song Liu <song@kernel.org>
Cc: Hao Luo <haoluo@google.com>
CC: bpf@vger.kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
---
tools/perf/util/bpf_off_cpu.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
Comments
On Fri, Sep 22, 2023 at 4:44 PM Namhyung Kim <namhyung@kernel.org> wrote: > > The BTF func proto for a tracepoint has one more argument than the > actual tracepoint function since it has a context argument at the > begining. So it should compare to 5 when the tracepoint has 4 > arguments. > > typedef void (*btf_trace_sched_switch)(void *, bool, struct task_struct *, struct task_struct *, unsigned int); > > Also, recent change in the perf tool would use a hand-written minimal > vmlinux.h to generate BTF in the skeleton. So it won't have the info > of the tracepoint. Anyway it should use the kernel's vmlinux BTF to > check the type in the kernel. > > Fixes: b36888f71c85 ("perf record: Handle argument change in sched_switch") > Cc: Song Liu <song@kernel.org> > Cc: Hao Luo <haoluo@google.com> > CC: bpf@vger.kernel.org > Signed-off-by: Namhyung Kim <namhyung@kernel.org> Reviewed-by: Ian Rogers <irogers@google.com> > --- > tools/perf/util/bpf_off_cpu.c | 5 +++-- > 1 file changed, 3 insertions(+), 2 deletions(-) > > diff --git a/tools/perf/util/bpf_off_cpu.c b/tools/perf/util/bpf_off_cpu.c > index 01f70b8e705a..21f4d9ba023d 100644 > --- a/tools/perf/util/bpf_off_cpu.c > +++ b/tools/perf/util/bpf_off_cpu.c > @@ -98,7 +98,7 @@ static void off_cpu_finish(void *arg __maybe_unused) > /* v5.18 kernel added prev_state arg, so it needs to check the signature */ > static void check_sched_switch_args(void) > { > - const struct btf *btf = bpf_object__btf(skel->obj); > + const struct btf *btf = btf__load_vmlinux_btf(); > const struct btf_type *t1, *t2, *t3; > u32 type_id; > > @@ -116,7 +116,8 @@ static void check_sched_switch_args(void) > return; > > t3 = btf__type_by_id(btf, t2->type); > - if (t3 && btf_is_func_proto(t3) && btf_vlen(t3) == 4) { > + /* btf_trace func proto has one more argument for the context */ > + if (t3 && btf_is_func_proto(t3) && btf_vlen(t3) == 5) { > /* new format: pass prev_state as 4th arg */ nit: does this comment need updating? > skel->rodata->has_prev_state = true; > } > -- > 2.42.0.515.g380fc7ccd1-goog >
Hi Ian, On Sun, Sep 24, 2023 at 11:03 AM Ian Rogers <irogers@google.com> wrote: > > On Fri, Sep 22, 2023 at 4:44 PM Namhyung Kim <namhyung@kernel.org> wrote: > > > > The BTF func proto for a tracepoint has one more argument than the > > actual tracepoint function since it has a context argument at the > > begining. So it should compare to 5 when the tracepoint has 4 > > arguments. > > > > typedef void (*btf_trace_sched_switch)(void *, bool, struct task_struct *, struct task_struct *, unsigned int); > > > > Also, recent change in the perf tool would use a hand-written minimal > > vmlinux.h to generate BTF in the skeleton. So it won't have the info > > of the tracepoint. Anyway it should use the kernel's vmlinux BTF to > > check the type in the kernel. > > > > Fixes: b36888f71c85 ("perf record: Handle argument change in sched_switch") > > Cc: Song Liu <song@kernel.org> > > Cc: Hao Luo <haoluo@google.com> > > CC: bpf@vger.kernel.org > > Signed-off-by: Namhyung Kim <namhyung@kernel.org> > > Reviewed-by: Ian Rogers <irogers@google.com> Thanks for the review! > > > --- > > tools/perf/util/bpf_off_cpu.c | 5 +++-- > > 1 file changed, 3 insertions(+), 2 deletions(-) > > > > diff --git a/tools/perf/util/bpf_off_cpu.c b/tools/perf/util/bpf_off_cpu.c > > index 01f70b8e705a..21f4d9ba023d 100644 > > --- a/tools/perf/util/bpf_off_cpu.c > > +++ b/tools/perf/util/bpf_off_cpu.c > > @@ -98,7 +98,7 @@ static void off_cpu_finish(void *arg __maybe_unused) > > /* v5.18 kernel added prev_state arg, so it needs to check the signature */ > > static void check_sched_switch_args(void) > > { > > - const struct btf *btf = bpf_object__btf(skel->obj); > > + const struct btf *btf = btf__load_vmlinux_btf(); > > const struct btf_type *t1, *t2, *t3; > > u32 type_id; > > > > @@ -116,7 +116,8 @@ static void check_sched_switch_args(void) > > return; > > > > t3 = btf__type_by_id(btf, t2->type); > > - if (t3 && btf_is_func_proto(t3) && btf_vlen(t3) == 4) { > > + /* btf_trace func proto has one more argument for the context */ > > + if (t3 && btf_is_func_proto(t3) && btf_vlen(t3) == 5) { > > /* new format: pass prev_state as 4th arg */ > > nit: does this comment need updating? No, it's the 4th arg and the sched_switch is called like. trace_sched_switch(sched_mode & SM_MASK_PREEMPT, prev, next, prev_state); Thanks, Namhyung
On Fri, Sep 22, 2023 at 4:44 PM Namhyung Kim <namhyung@kernel.org> wrote: > > The BTF func proto for a tracepoint has one more argument than the > actual tracepoint function since it has a context argument at the > begining. So it should compare to 5 when the tracepoint has 4 > arguments. > > typedef void (*btf_trace_sched_switch)(void *, bool, struct task_struct *, struct task_struct *, unsigned int); > > Also, recent change in the perf tool would use a hand-written minimal > vmlinux.h to generate BTF in the skeleton. So it won't have the info > of the tracepoint. Anyway it should use the kernel's vmlinux BTF to > check the type in the kernel. > > Fixes: b36888f71c85 ("perf record: Handle argument change in sched_switch") > Cc: Song Liu <song@kernel.org> > Cc: Hao Luo <haoluo@google.com> > CC: bpf@vger.kernel.org > Signed-off-by: Namhyung Kim <namhyung@kernel.org> Acked-by: Song Liu <song@kernel.org>
On Wed, Sep 27, 2023 at 9:09 AM Song Liu <song@kernel.org> wrote: > > On Fri, Sep 22, 2023 at 4:44 PM Namhyung Kim <namhyung@kernel.org> wrote: > > > > The BTF func proto for a tracepoint has one more argument than the > > actual tracepoint function since it has a context argument at the > > begining. So it should compare to 5 when the tracepoint has 4 > > arguments. > > > > typedef void (*btf_trace_sched_switch)(void *, bool, struct task_struct *, struct task_struct *, unsigned int); > > > > Also, recent change in the perf tool would use a hand-written minimal > > vmlinux.h to generate BTF in the skeleton. So it won't have the info > > of the tracepoint. Anyway it should use the kernel's vmlinux BTF to > > check the type in the kernel. > > > > Fixes: b36888f71c85 ("perf record: Handle argument change in sched_switch") > > Cc: Song Liu <song@kernel.org> > > Cc: Hao Luo <haoluo@google.com> > > CC: bpf@vger.kernel.org > > Signed-off-by: Namhyung Kim <namhyung@kernel.org> > > Acked-by: Song Liu <song@kernel.org> Applied to perf-tools-next, thanks!
diff --git a/tools/perf/util/bpf_off_cpu.c b/tools/perf/util/bpf_off_cpu.c index 01f70b8e705a..21f4d9ba023d 100644 --- a/tools/perf/util/bpf_off_cpu.c +++ b/tools/perf/util/bpf_off_cpu.c @@ -98,7 +98,7 @@ static void off_cpu_finish(void *arg __maybe_unused) /* v5.18 kernel added prev_state arg, so it needs to check the signature */ static void check_sched_switch_args(void) { - const struct btf *btf = bpf_object__btf(skel->obj); + const struct btf *btf = btf__load_vmlinux_btf(); const struct btf_type *t1, *t2, *t3; u32 type_id; @@ -116,7 +116,8 @@ static void check_sched_switch_args(void) return; t3 = btf__type_by_id(btf, t2->type); - if (t3 && btf_is_func_proto(t3) && btf_vlen(t3) == 4) { + /* btf_trace func proto has one more argument for the context */ + if (t3 && btf_is_func_proto(t3) && btf_vlen(t3) == 5) { /* new format: pass prev_state as 4th arg */ skel->rodata->has_prev_state = true; }