Message ID | 20221102160236.11696-1-iecedge@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a40e:b0:83:7221:86ba with SMTP id ck14csp59534dyb; Wed, 2 Nov 2022 09:06:57 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5iD/ELhAsaPhELw2uqjpjak4uLt3GQFOILXUm5vgRngRQRlOt3dRpszNKbsUrump/oRqaO X-Received: by 2002:a17:907:6e93:b0:78d:dff1:71e3 with SMTP id sh19-20020a1709076e9300b0078ddff171e3mr23222352ejc.94.1667405216805; Wed, 02 Nov 2022 09:06:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667405216; cv=none; d=google.com; s=arc-20160816; b=N6Ap+GyuL+zrSpUmllFDpCzOi3B3zy2RX616hvxmuwVwh0RBdtTVLuln+3625HLQ60 gRbPfCEGz5gPbHH+YaLVBCVTs9wcdjKCbIEUa0iTXI+0SQwQ4d8GbV9Q+e9T3OzMk4E5 137RA4Uovs8RoKiOmvwbyzd2j/pDhEqY3z6dc5VZzH/d9gTA7zESL2W37dwSSljNO/QG Mjr5lM6McwUiw8utbKEs7QyeUHiWoExJR57bO3nXxhUvWwIRJzbUoJGl5GJLTqES1K2T KDQRA2MKRCZKYTXOdufWLZjqZQjgWicAdAF7FuB+V0YWE2vVKgd3W9qCBqi2Jts1LMT2 a2DQ== 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:dkim-signature; bh=xv6cL0ZSGPHAFthg9NzBypc1kXfNTRd7Jr+ckvgr8EQ=; b=ubRLm6+usiGn/sXOZbnSjQNjRHsX69aM+KykgRQQhJN4KKo1204C1eq63mbChcu1w1 KCL2IhgccETUGXNpRG/RKqGTHZvON0bK4aXCk8Wu7mL93yhShDf44+6xVt/wDqQZY6lV KPWPJDu29VXmxI3//oa45SLjwjJ4C9wL66CqsBXsVHYx4HAyoTccxycshJUxaKCRl+K3 9XrMe3SpQKCtLEObMDMf/9x8M8i2szuSYBARwXEeCqhnrTFzIOSrzhmvUqGdciA64ypG g+0qKwcwfS1BOPotstTIVJIUzLP+923t1sQasidKY4I0JpGWNrxnuUoKYdQs2xCpMtwl Noww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=dUREi1KB; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id hz5-20020a1709072ce500b007919c624eadsi16660944ejc.522.2022.11.02.09.06.28; Wed, 02 Nov 2022 09:06:56 -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=pass header.i=@gmail.com header.s=20210112 header.b=dUREi1KB; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231303AbiKBQEx (ORCPT <rfc822;yves.mi.zy@gmail.com> + 99 others); Wed, 2 Nov 2022 12:04:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43896 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231279AbiKBQEf (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 2 Nov 2022 12:04:35 -0400 Received: from mail-io1-xd2d.google.com (mail-io1-xd2d.google.com [IPv6:2607:f8b0:4864:20::d2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37FDF2D1D8 for <linux-kernel@vger.kernel.org>; Wed, 2 Nov 2022 09:03:58 -0700 (PDT) Received: by mail-io1-xd2d.google.com with SMTP id b2so482547iof.12 for <linux-kernel@vger.kernel.org>; Wed, 02 Nov 2022 09:03:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=xv6cL0ZSGPHAFthg9NzBypc1kXfNTRd7Jr+ckvgr8EQ=; b=dUREi1KBpt9LKyWLyHp/8nfkpssv9BdL8zcw/pvQpoq/Or0dteNa8SRDWqgYgxgkZE tBFxFMz8GzAnftA32BARgBUOw8C88DN0j3DRBXv9GkKOrpv4Fn9qEriYc0tXa819vRSY TQGQ8uqIMmtvNyBjhoUfr8R7JFtlCj4876sZpx4mHs+wsqWpit8knC5JBw4B8hGK61aj NmRTHB5i5hXKQHZ/2q3EOLVwJllhfRtCqQbILdt0MsN1iHoAC3bk52Tb33ooi2For1xD ZHObNdB/C8W3uq6fl0CSB14xWG0jEwoMPxorHVWB7a1+k1A20gGkIM/go2wANBsyRjRI ecFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=xv6cL0ZSGPHAFthg9NzBypc1kXfNTRd7Jr+ckvgr8EQ=; b=SpU2UyLBh31eiXIwN/RvD5d7E6cEW2Hn7TL1Qn7Exq8vdJkp4MuDzJJyGLZtEb3AZB 6Ociv6Qi+74CKtFJcSt73gRskAeB0KXgOsb9VbybIbKG0nBaQh0pZl8XyAoMC+kn9Jrr BCIoJNeGrqsZQjlnangu1ftQRj0ZHfFXaWQsQXzTUzcbLvJw7Lfn/HScG776N2a4WgN7 4UTjKdU+4tTNy9SeGtQ1DCV0iTF2yENWCNXwo4q3LtY2taO2falggizwfxi6hkZ7lbA9 gKwBsquNqNgmKGrVHOYwmuLnvu/uETXh50bBSQeNzldj8yZNfk2DP00dwSanfMGjtawX gGaA== X-Gm-Message-State: ACrzQf1J6Qk3HwBFg5GokKUpgaLLrYz3hMTQAqy5UOcQQ4jfl7wfU6fi XKbSnAuvUmMtlSj93rZ3k17rxBvh1zbnsRSv X-Received: by 2002:a05:6638:304c:b0:363:ff68:8ebc with SMTP id u12-20020a056638304c00b00363ff688ebcmr17337143jak.294.1667405037604; Wed, 02 Nov 2022 09:03:57 -0700 (PDT) Received: from ip-172-31-23-7.us-east-2.compute.internal (ec2-52-14-118-98.us-east-2.compute.amazonaws.com. [52.14.118.98]) by smtp.googlemail.com with ESMTPSA id y4-20020a92d804000000b002f66aacb98asm4704327ilm.70.2022.11.02.09.03.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Nov 2022 09:03:56 -0700 (PDT) From: Jianlin Lv <iecedge@gmail.com> To: rostedt@goodmis.org, alison.schofield@intel.com, davidgow@google.com, thunder.leizhen@huawei.com Cc: iecedge@gmail.com, jianlv@ebay.com, linux-kernel@vger.kernel.org Subject: [PATCH] tracepoint: Allow livepatch module add trace event Date: Wed, 2 Nov 2022 16:02:36 +0000 Message-Id: <20221102160236.11696-1-iecedge@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham 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?1748401093076876947?= X-GMAIL-MSGID: =?utf-8?q?1748401093076876947?= |
Series |
tracepoint: Allow livepatch module add trace event
|
|
Commit Message
Jianlin Lv
Nov. 2, 2022, 4:02 p.m. UTC
In the case of keeping the system running, the preferred method for
tracing the kernel is dynamic tracing (kprobe), but the drawback of
this method is that events are lost, especially when tracing packages
in the network stack.
Livepatching provides a potential solution, which is to reimplement the
function you want to replace and insert a static tracepoint.
In such a way, custom stable static tracepoints can be expanded without
rebooting the system.
Signed-off-by: Jianlin Lv <iecedge@gmail.com>
---
kernel/tracepoint.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
Comments
On Wed, 2 Nov 2022 16:02:36 +0000 Jianlin Lv <iecedge@gmail.com> wrote: > In the case of keeping the system running, the preferred method for > tracing the kernel is dynamic tracing (kprobe), but the drawback of > this method is that events are lost, especially when tracing packages > in the network stack. > > Livepatching provides a potential solution, which is to reimplement the > function you want to replace and insert a static tracepoint. > In such a way, custom stable static tracepoints can be expanded without > rebooting the system. Well that's definitely one way to implement dynamic trace events! :-D -- Steve > > Signed-off-by: Jianlin Lv <iecedge@gmail.com> > --- > kernel/tracepoint.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/kernel/tracepoint.c b/kernel/tracepoint.c > index f23144af5743..8d1507dd0724 100644 > --- a/kernel/tracepoint.c > +++ b/kernel/tracepoint.c > @@ -571,8 +571,8 @@ static void for_each_tracepoint_range( > bool trace_module_has_bad_taint(struct module *mod) > { > return mod->taints & ~((1 << TAINT_OOT_MODULE) | (1 << TAINT_CRAP) | > - (1 << TAINT_UNSIGNED_MODULE) | > - (1 << TAINT_TEST)); > + (1 << TAINT_UNSIGNED_MODULE) | (1 << TAINT_TEST) | > + (1 << TAINT_LIVEPATCH)); > } > > static BLOCKING_NOTIFIER_HEAD(tracepoint_notify_list);
On Wed, 2 Nov 2022 16:02:36 +0000 Jianlin Lv <iecedge@gmail.com> wrote: > In the case of keeping the system running, the preferred method for > tracing the kernel is dynamic tracing (kprobe), but the drawback of > this method is that events are lost, especially when tracing packages > in the network stack. I'm not against this change, but the above is where I'm a bit confused. How are events more likely to be lost with kprobes over a static event? -- Steve
On Tue, Nov 15, 2022 at 1:22 AM Steven Rostedt <rostedt@goodmis.org> wrote: > > On Wed, 2 Nov 2022 16:02:36 +0000 > Jianlin Lv <iecedge@gmail.com> wrote: > > > In the case of keeping the system running, the preferred method for > > tracing the kernel is dynamic tracing (kprobe), but the drawback of > > this method is that events are lost, especially when tracing packages > > in the network stack. > > I'm not against this change, but the above is where I'm a bit confused. How > are events more likely to be lost with kprobes over a static event? We have encountered a case of kprobes missing event, detailed information can refer to the following link: https://github.com/iovisor/bcc/issues/4198 Replacing kprobe with ’bpf + raw tracepoint‘, no missing events occur. > -- Steve
On Tue, 15 Nov 2022 10:38:34 +0800 Jianlin Lv <iecedge@gmail.com> wrote: > On Tue, Nov 15, 2022 at 1:22 AM Steven Rostedt <rostedt@goodmis.org> wrote: > > > > On Wed, 2 Nov 2022 16:02:36 +0000 > > Jianlin Lv <iecedge@gmail.com> wrote: > > > > > In the case of keeping the system running, the preferred method for > > > tracing the kernel is dynamic tracing (kprobe), but the drawback of > > > this method is that events are lost, especially when tracing packages > > > in the network stack. > > > > I'm not against this change, but the above is where I'm a bit confused. How > > are events more likely to be lost with kprobes over a static event? > > We have encountered a case of kprobes missing event, detailed > information can refer to the following link: > https://github.com/iovisor/bcc/issues/4198 > > Replacing kprobe with ’bpf + raw tracepoint‘, no missing events occur. > Masami, What's the reason that kprobes are not re-entrant when using ftrace? -- Steve
On Mon, 14 Nov 2022 22:02:16 -0500 Steven Rostedt <rostedt@goodmis.org> wrote: > On Tue, 15 Nov 2022 10:38:34 +0800 > Jianlin Lv <iecedge@gmail.com> wrote: > > > On Tue, Nov 15, 2022 at 1:22 AM Steven Rostedt <rostedt@goodmis.org> wrote: > > > > > > On Wed, 2 Nov 2022 16:02:36 +0000 > > > Jianlin Lv <iecedge@gmail.com> wrote: > > > > > > > In the case of keeping the system running, the preferred method for > > > > tracing the kernel is dynamic tracing (kprobe), but the drawback of > > > > this method is that events are lost, especially when tracing packages > > > > in the network stack. > > > > > > I'm not against this change, but the above is where I'm a bit confused. How > > > are events more likely to be lost with kprobes over a static event? > > > > We have encountered a case of kprobes missing event, detailed > > information can refer to the following link: > > https://github.com/iovisor/bcc/issues/4198 > > > > Replacing kprobe with ’bpf + raw tracepoint‘, no missing events occur. > > > > Masami, > > What's the reason that kprobes are not re-entrant when using ftrace? I think we had discussed this issue when I drop the irq_disable() from kprobe ftrace handler on x86, see commit a19b2e3d7839 ("kprobes/x86: Remove IRQ disabling from ftrace-based/optimized kprobes"). Anyway, kprobes itself is not re-entrant (and no need to be re-entrant when using int3) because it uses a per-cpu variable to memorize the current running kprobes while processing the int3 handling and the singlestep (trap) handling so that it can go back to the correct track safely. It also has a single-stage "backup" (see save_previous_kprobe()) for unexpectedly re-entrant kprobes (e.g. call a probed function from kprobe user handler.) Thus the kprobe user doesn't need to write a re-entrant handler code. Since kprobes on function entry is transparently changed to the ftrace, we have to keep this limitation on the kprobes on ftrace. BTW, now the kprobe_ftrace_handler() uses ftrace_test_recursion_trylock() to avoid ftrace recursion, is that OK for this case? Thank you,
On Wed, 16 Nov 2022 00:07:07 +0900 Masami Hiramatsu (Google) <mhiramat@kernel.org> wrote: > BTW, now the kprobe_ftrace_handler() uses ftrace_test_recursion_trylock() > to avoid ftrace recursion, is that OK for this case? Note, the ftrace_test_recursion_trylock() only prevents "same context" recursion. That is, it will not let normal context recurse into normal context, or interrupt context recurse into interrupt context. It has the logic of breaking up into 4 levels: 1. normal 2. softirq 3. irq 4. NMI It allows the high levels to recurse into lower levels (e.g. irq context into normal context) Thus, the code within the ftrace_test_recursion_trylock() must itself be re-entrant to handle being called from different contexts. -- Steve
On Tue, Nov 15, 2022 at 11:17 PM Steven Rostedt <rostedt@goodmis.org> wrote: > > On Wed, 16 Nov 2022 00:07:07 +0900 > Masami Hiramatsu (Google) <mhiramat@kernel.org> wrote: > > > BTW, now the kprobe_ftrace_handler() uses ftrace_test_recursion_trylock() > > to avoid ftrace recursion, is that OK for this case? > > Note, the ftrace_test_recursion_trylock() only prevents "same context" > recursion. That is, it will not let normal context recurse into normal > context, or interrupt context recurse into interrupt context. > > It has the logic of breaking up into 4 levels: > > 1. normal > 2. softirq > 3. irq > 4. NMI > > It allows the high levels to recurse into lower levels > (e.g. irq context into normal context) > > Thus, the code within the ftrace_test_recursion_trylock() must itself be > re-entrant to handle being called from different contexts. > > -- Steve hi, Steve Any other comments for code changes? Is it possible for this patch to be merged? Regards, Jianlin
On Fri, 23 Dec 2022 12:52:18 +0800 Jianlin Lv <iecedge@gmail.com> wrote: > hi, Steve > Any other comments for code changes? > Is it possible for this patch to be merged? Ah, I had it marked as waiting for a reply. But I think we got side tracked on the discussion. Anyway, this is a trivial patch, I think I can get it in during -rc1. -- Steve
On Fri, 23 Dec 2022 00:08:08 -0500 Steven Rostedt <rostedt@goodmis.org> wrote: > On Fri, 23 Dec 2022 12:52:18 +0800 > Jianlin Lv <iecedge@gmail.com> wrote: > > > hi, Steve > > Any other comments for code changes? > > Is it possible for this patch to be merged? > > Ah, I had it marked as waiting for a reply. But I think we got side > tracked on the discussion. > > Anyway, this is a trivial patch, I think I can get it in during -rc1. > And it appears that due to the Christmas holidays, I dropped the patch. I'm adding it to the queue now. -- Steve
diff --git a/kernel/tracepoint.c b/kernel/tracepoint.c index f23144af5743..8d1507dd0724 100644 --- a/kernel/tracepoint.c +++ b/kernel/tracepoint.c @@ -571,8 +571,8 @@ static void for_each_tracepoint_range( bool trace_module_has_bad_taint(struct module *mod) { return mod->taints & ~((1 << TAINT_OOT_MODULE) | (1 << TAINT_CRAP) | - (1 << TAINT_UNSIGNED_MODULE) | - (1 << TAINT_TEST)); + (1 << TAINT_UNSIGNED_MODULE) | (1 << TAINT_TEST) | + (1 << TAINT_LIVEPATCH)); } static BLOCKING_NOTIFIER_HEAD(tracepoint_notify_list);