Message ID | 41828b90.5798.18442c10017.Coremail.00107082@163.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp389878wru; Fri, 4 Nov 2022 06:08:37 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6cE+dHUuZLnd7UmvvUAZqlibFdy2C4Syx4sYLuGN8i1Qxxlpx8FlOwxJTGOqEKIhELKnms X-Received: by 2002:a17:90b:4c07:b0:213:44f5:6073 with SMTP id na7-20020a17090b4c0700b0021344f56073mr36660027pjb.184.1667567317362; Fri, 04 Nov 2022 06:08:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667567317; cv=none; d=google.com; s=arc-20160816; b=JnlaY1bN28G9M7otxnwaRxdvn/Sjlmbk5b9uJpxLBYcRRC5jauXIDtnIM17sMDCFLH Hf92cyYZ+R2HM3XjCe3361L7YFXfSFf2SC+b5rlbFu3jut9aUO5GXZXTnFQF8kymAKvA /LotC74SkFUPOXcM/Pjyu1xDRBS6aaXOdLcYgwUjy1TcJMPlN75U1jR7VE0+aMByxCyG 0QE0DnZLmVVAAsk4JJqJ9FEtVPDXs5YrCM+sYOAkd5b/gA4mvGtNhU9sRHQ0wvhDROQ7 ABw1BZcsLMMFOJoIqV6/2rMH1vX7dR/I9PMZ8oM47PNjtYW8yEkYTmM8LMBoyTV/0q9C IGdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:mime-version :content-transfer-encoding:subject:to:from:date:dkim-signature; bh=E+XzMKU05SBCjZ1akHyN80VngofkywOG1jO+qLwFMRQ=; b=u3XfbabYqWpdQFOlqUecXd8+lQbmqbS65RNyoYPh78yZA8cBrB/wBWdjea+JtrPlXc Y2QiM1dUH4R6cOkIkGJw5YppO6gYwNLdK1RBKYhAxIfDvleXj6+gfun1PNcK6NWg2PLa i7K0jyGE3khJDpSZvcbBD5FN3JYUz7UZebvhrp0JE+9jm8jh8bHFgsB6E4wS9rUEIzvJ 2kulSAOr3+mW0lyqLh4GF5Mf35XUED6a+/NRyLpzvZtC9OqCgJtxD2d2iJfEqwZzZl8A 4BVuraTfGhM+zUGRZfqqEDdXTHMlwk0yKIMjKqOLmAzOUTAPDVqMkOghp4/K7qF/lZAO CIJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@163.com header.s=s110527 header.b="Yp/+ETeK"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=163.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f15-20020a63f10f000000b0045ce0eba520si904202pgi.751.2022.11.04.06.08.18; Fri, 04 Nov 2022 06:08:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@163.com header.s=s110527 header.b="Yp/+ETeK"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=163.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230205AbiKDNHl (ORCPT <rfc822;jimliu8233@gmail.com> + 99 others); Fri, 4 Nov 2022 09:07:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230021AbiKDNHj (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 4 Nov 2022 09:07:39 -0400 Received: from m13134.mail.163.com (m13134.mail.163.com [220.181.13.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 89F142E6B9 for <linux-kernel@vger.kernel.org>; Fri, 4 Nov 2022 06:07:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=Date:From:Subject:MIME-Version:Message-ID; bh=M9PbT Gakjv/3zqqgp2j3iH+TiftOFmtoxz74GES9Wdo=; b=Yp/+ETeK6T2LXqYxNALmY CjF/byF4HURdXx4RLah+6zhP35r5VkVwOboxj1jrufD3Huwl3mLjk2nmx5qKIukL jH4Wm9IVgMZ82BCTNoxEw7M2dmVa305eNgdRcpXK/+l17Guqna9gmuaoq4IT3hmJ RsPUcQbRcv+LsrJ3c2keeM= Received: from 00107082$163.com ( [222.64.157.165] ) by ajax-webmail-wmsvr134 (Coremail) ; Fri, 4 Nov 2022 21:07:35 +0800 (CST) X-Originating-IP: [222.64.157.165] Date: Fri, 4 Nov 2022 21:07:35 +0800 (CST) From: "David Wang" <00107082@163.com> To: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org> Subject: [PATCH] trace/trace_uprobe: Only invoke uprobe ebpf handler when event matches. X-Priority: 3 X-Mailer: Coremail Webmail Server Version XT5.0.13 build 20220113(9671e152) Copyright (c) 2002-2022 www.mailtech.cn 163com X-NTES-SC: AL_QuydBfmduEou4yWfZekZnEoUjug3W8K5v/kk3Y9VOp80iivC1Q4adlVPLEL4686kOQeHmjKpQSRf6PtgR4pKcqx5q1y7eiLUqlPJsufzuHT5 Content-Transfer-Encoding: base64 Content-Type: text/plain; charset=GBK MIME-Version: 1.0 Message-ID: <41828b90.5798.18442c10017.Coremail.00107082@163.com> X-Coremail-Locale: zh_CN X-CM-TRANSID: hsGowACH_t2XDmVjmj5cAA--.49235W X-CM-SenderInfo: qqqrilqqysqiywtou0bp/1tbiEAivql8YLKr7GgABs8 X-Coremail-Antispam: 1U5529EdanIXcx71UUUUU7vcSsGvfC2KfnxnUU== X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,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 lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748571067213768119?= X-GMAIL-MSGID: =?utf-8?q?1748571067213768119?= |
Series |
trace/trace_uprobe: Only invoke uprobe ebpf handler when event matches.
|
|
Commit Message
David Wang
Nov. 4, 2022, 1:07 p.m. UTC
Only invoke uprobe ebpf handler when event matches.
uprobe ebpf handler would be called even the event dose not
match any registered perf event, following steps would be
used to generate a unregistered perf event.
1. register a uprobe event on a specified pid <pid-a>
2. <pid-a> invokes syscall `clone` (via pthread_create),
new process <pid-b> generated. (Maybe it is a bug here, the
uprobe breakpoint is inherited from <pid-a>
3. <pid-b> invokes the function which is uprobed in step 1.
4. perf event generated...
Ebpf handler would be invoked even the event happened on <pid-b>,
but the default perf event handler make further check and ignore
the event because no registered perf event match on <pid-b>.
The patch means to fix the inconsistent behavior between ebpf and the default.
Before invoke uprobe ebpf handler, make sure current event match.
Signed-off-by: David Wang <00107082@163.com>
--
--
Comments
Hi David, Thank you for the patch! Perhaps something to improve: [auto build test WARNING on linus/master] [also build test WARNING on v6.1-rc3 next-20221104] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/David-Wang/trace-trace_uprobe-Only-invoke-uprobe-ebpf-handler-when-event-matches/20221104-210925 patch link: https://lore.kernel.org/r/41828b90.5798.18442c10017.Coremail.00107082%40163.com patch subject: [PATCH] trace/trace_uprobe: Only invoke uprobe ebpf handler when event matches. config: i386-defconfig compiler: gcc-11 (Debian 11.3.0-8) 11.3.0 reproduce (this is a W=1 build): # https://github.com/intel-lab-lkp/linux/commit/6c778c475c0a6c8a11c1a74705a5856681cf6cf0 git remote add linux-review https://github.com/intel-lab-lkp/linux git fetch --no-tags linux-review David-Wang/trace-trace_uprobe-Only-invoke-uprobe-ebpf-handler-when-event-matches/20221104-210925 git checkout 6c778c475c0a6c8a11c1a74705a5856681cf6cf0 # save the config file mkdir build_dir && cp config build_dir/.config make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash kernel/trace/ If you fix the issue, kindly add following tag where applicable | Reported-by: kernel test robot <lkp@intel.com> All warnings (new ones prefixed by >>): kernel/trace/trace_uprobe.c: In function '__uprobe_perf_func': >> kernel/trace/trace_uprobe.c:1349:14: warning: variable 'trace_event_match' set but not used [-Wunused-but-set-variable] 1349 | bool trace_event_match = true; | ^~~~~~~~~~~~~~~~~ vim +/trace_event_match +1349 kernel/trace/trace_uprobe.c 1338 1339 static void __uprobe_perf_func(struct trace_uprobe *tu, 1340 unsigned long func, struct pt_regs *regs, 1341 struct uprobe_cpu_buffer *ucb, int dsize) 1342 { 1343 struct trace_event_call *call = trace_probe_event_call(&tu->tp); 1344 struct uprobe_trace_entry_head *entry; 1345 struct hlist_head *head; 1346 void *data; 1347 int size, esize; 1348 int rctx; > 1349 bool trace_event_match = true; 1350 1351 1352 preempt_disable(); 1353 head = this_cpu_ptr(call->perf_events); 1354 if (hlist_empty(head)) { 1355 trace_event_match = false; 1356 goto out; 1357 } 1358 1359 esize = SIZEOF_TRACE_ENTRY(is_ret_probe(tu)); 1360 size = esize + tu->tp.size + dsize; 1361 size = ALIGN(size + sizeof(u32), sizeof(u64)) - sizeof(u32); 1362 if (WARN_ONCE(size > PERF_MAX_TRACE_SIZE, "profile buffer not large enough")) 1363 goto out; 1364 1365 entry = perf_trace_buf_alloc(size, NULL, &rctx); 1366 if (!entry) 1367 goto out; 1368 1369 if (is_ret_probe(tu)) { 1370 entry->vaddr[0] = func; 1371 entry->vaddr[1] = instruction_pointer(regs); 1372 data = DATAOF_TRACE_ENTRY(entry, true); 1373 } else { 1374 entry->vaddr[0] = instruction_pointer(regs); 1375 data = DATAOF_TRACE_ENTRY(entry, false); 1376 } 1377 1378 memcpy(data, ucb->buf, tu->tp.size + dsize); 1379 1380 if (size - esize > tu->tp.size + dsize) { 1381 int len = tu->tp.size + dsize; 1382 1383 memset(data + len, 0, size - esize - len); 1384 } 1385 perf_trace_buf_submit(entry, size, rctx, call->event.type, 1, regs, 1386 head, NULL); 1387 out: 1388 preempt_enable(); 1389
Fix compile warning: unused variable trace_event_match `trace_event_match` is used to indicate whether current event matches any registered event. For now, this variable is only used for ebpf handler and CONFIG_BPF_EVENTS is needed, otherwise a compile warning would be generated about unused variable. Reported-by: kernel test robot <lkp@intel.com> Signed-off-by: David Wang <00107082@163.com> -- diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c index 6f13163c0c0f..0548c651699e 100644 --- a/kernel/trace/trace_uprobe.c +++ b/kernel/trace/trace_uprobe.c @@ -1346,13 +1346,17 @@ static void __uprobe_perf_func(struct trace_uprobe *tu, void *data; int size, esize; int rctx; +#ifdef CONFIG_BPF_EVENTS bool trace_event_match = true; +#endif /* CONFIG_BPF_EVENTS */ preempt_disable(); head = this_cpu_ptr(call->perf_events); if (hlist_empty(head)) { +#ifdef CONFIG_BPF_EVENTS trace_event_match = false; +#endif /* CONFIG_BPF_EVENTS */ goto out; } -- At 2022-11-05 05:30:37, "kernel test robot" <lkp@intel.com> wrote: >Hi David, > >Thank you for the patch! Perhaps something to improve: > >[auto build test WARNING on linus/master] >[also build test WARNING on v6.1-rc3 next-20221104] >[If your patch is applied to the wrong git tree, kindly drop us a note. >And when submitting patch, we suggest to use '--base' as documented in >https://git-scm.com/docs/git-format-patch#_base_tree_information] > >url: https://github.com/intel-lab-lkp/linux/commits/David-Wang/trace-trace_uprobe-Only-invoke-uprobe-ebpf-handler-when-event-matches/20221104-210925 >patch link: https://lore.kernel.org/r/41828b90.5798.18442c10017.Coremail.00107082%40163.com >patch subject: [PATCH] trace/trace_uprobe: Only invoke uprobe ebpf handler when event matches. >config: i386-defconfig >compiler: gcc-11 (Debian 11.3.0-8) 11.3.0 >reproduce (this is a W=1 build): > # https://github.com/intel-lab-lkp/linux/commit/6c778c475c0a6c8a11c1a74705a5856681cf6cf0 > git remote add linux-review https://github.com/intel-lab-lkp/linux > git fetch --no-tags linux-review David-Wang/trace-trace_uprobe-Only-invoke-uprobe-ebpf-handler-when-event-matches/20221104-210925 > git checkout 6c778c475c0a6c8a11c1a74705a5856681cf6cf0 > # save the config file > mkdir build_dir && cp config build_dir/.config > make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash kernel/trace/ > >If you fix the issue, kindly add following tag where applicable >| Reported-by: kernel test robot <lkp@intel.com> > >All warnings (new ones prefixed by >>): > > kernel/trace/trace_uprobe.c: In function '__uprobe_perf_func': >>> kernel/trace/trace_uprobe.c:1349:14: warning: variable 'trace_event_match' set but not used [-Wunused-but-set-variable] > 1349 | bool trace_event_match = true; > | ^~~~~~~~~~~~~~~~~ > > >vim +/trace_event_match +1349 kernel/trace/trace_uprobe.c > > 1338 > 1339 static void __uprobe_perf_func(struct trace_uprobe *tu, > 1340 unsigned long func, struct pt_regs *regs, > 1341 struct uprobe_cpu_buffer *ucb, int dsize) > 1342 { > 1343 struct trace_event_call *call = trace_probe_event_call(&tu->tp); > 1344 struct uprobe_trace_entry_head *entry; > 1345 struct hlist_head *head; > 1346 void *data; > 1347 int size, esize; > 1348 int rctx; >> 1349 bool trace_event_match = true; > 1350 > 1351 > 1352 preempt_disable(); > 1353 head = this_cpu_ptr(call->perf_events); > 1354 if (hlist_empty(head)) { > 1355 trace_event_match = false; > 1356 goto out; > 1357 } > 1358 > 1359 esize = SIZEOF_TRACE_ENTRY(is_ret_probe(tu)); > 1360 size = esize + tu->tp.size + dsize; > 1361 size = ALIGN(size + sizeof(u32), sizeof(u64)) - sizeof(u32); > 1362 if (WARN_ONCE(size > PERF_MAX_TRACE_SIZE, "profile buffer not large enough")) > 1363 goto out; > 1364 > 1365 entry = perf_trace_buf_alloc(size, NULL, &rctx); > 1366 if (!entry) > 1367 goto out; > 1368 > 1369 if (is_ret_probe(tu)) { > 1370 entry->vaddr[0] = func; > 1371 entry->vaddr[1] = instruction_pointer(regs); > 1372 data = DATAOF_TRACE_ENTRY(entry, true); > 1373 } else { > 1374 entry->vaddr[0] = instruction_pointer(regs); > 1375 data = DATAOF_TRACE_ENTRY(entry, false); > 1376 } > 1377 > 1378 memcpy(data, ucb->buf, tu->tp.size + dsize); > 1379 > 1380 if (size - esize > tu->tp.size + dsize) { > 1381 int len = tu->tp.size + dsize; > 1382 > 1383 memset(data + len, 0, size - esize - len); > 1384 } > 1385 perf_trace_buf_submit(entry, size, rctx, call->event.type, 1, regs, > 1386 head, NULL); > 1387 out: > 1388 preempt_enable(); > 1389 > >-- >0-DAY CI Kernel Test Service >https://01.org/lkp
diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c index fb58e86dd117..6f13163c0c0f 100644 --- a/kernel/trace/trace_uprobe.c +++ b/kernel/trace/trace_uprobe.c @@ -1346,27 +1346,20 @@ static void __uprobe_perf_func(struct trace_uprobe *tu, void *data; int size, esize; int rctx; + bool trace_event_match = true; -#ifdef CONFIG_BPF_EVENTS - if (bpf_prog_array_valid(call)) { - u32 ret; - ret = bpf_prog_run_array_sleepable(call->prog_array, regs, bpf_prog_run); - if (!ret) - return; + preempt_disable(); + head = this_cpu_ptr(call->perf_events); + if (hlist_empty(head)) { + trace_event_match = false; + goto out; } -#endif /* CONFIG_BPF_EVENTS */ esize = SIZEOF_TRACE_ENTRY(is_ret_probe(tu)); - size = esize + tu->tp.size + dsize; size = ALIGN(size + sizeof(u32), sizeof(u64)) - sizeof(u32); if (WARN_ONCE(size > PERF_MAX_TRACE_SIZE, "profile buffer not large enough")) - return; - - preempt_disable(); - head = this_cpu_ptr(call->perf_events); - if (hlist_empty(head)) goto out; entry = perf_trace_buf_alloc(size, NULL, &rctx); @@ -1389,11 +1382,21 @@ static void __uprobe_perf_func(struct trace_uprobe *tu, memset(data + len, 0, size - esize - len); } - perf_trace_buf_submit(entry, size, rctx, call->event.type, 1, regs, head, NULL); out: preempt_enable(); + +#ifdef CONFIG_BPF_EVENTS + if (trace_event_match && bpf_prog_array_valid(call)) { + u32 ret; + + ret = bpf_prog_run_array_sleepable(call->prog_array, regs, bpf_prog_run); + if (!ret) + return; + } +#endif /* CONFIG_BPF_EVENTS */ + } /* uprobe profile handler */