Message ID | 20221110081502.492289-1-wuqiang.matt@bytedance.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 l7csp14770wru; Thu, 10 Nov 2022 00:17:45 -0800 (PST) X-Google-Smtp-Source: AMsMyM77yE3tJafi5pvqdhllouoDrlGdbfuWXlfMsPWciCO2x8ovwwfvaSFFi98ObgQg5eZzTExi X-Received: by 2002:a05:6402:74c:b0:462:2426:49d1 with SMTP id p12-20020a056402074c00b00462242649d1mr1862106edy.195.1668068264930; Thu, 10 Nov 2022 00:17:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668068264; cv=none; d=google.com; s=arc-20160816; b=iFUyThVdCfWO8C8ZkcBe4sf/nA8afTGPMP3wHouk/ErhnkkDw8xsT5EjD2HnPmUvK0 BBYXcYN/UOO9bUjVEBbyK2OzLKL1fOJ24TX0JRNpN2+pNdFxGx1842OI4GkyQOsIPiDx ipiovDBRW+lVWRrjI/BbuBATJZ0RJPu15mdfVSdSR3erkF3e/4eYf8ktjp64OxJ91B6x xItzSrFnK6BSD5b0MnbtphUlUL0dwSAiuMkshG2SPzCZojR0R4ylgs/5pk2323NDv0lH QmBqVRLOhT40EacvOrIXQpNkYvpED7UhjqIVvK75jci85GOXcOP9d9UTj6/O27g6bC9Z +tiQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1JiyZ1hWVATL+iuWQbgLK9dDD8NJ+KjIJFMCcv1dNws=; b=vBaYNMYdEEJ6YZOxkSVO2wDIJQwlKXYwI853TFUkdZ1hVProdigMSMyOd9hY/ZfXN8 WF3y320R969tXh2pPwePHk/soQs4esUwjpXAhv+ltLlE8dE8M5g7WTKCsfJLgD+5Wkzg gqkA/8U/QoxPNlzEgVNz9/3U30eurcbbgEDoegORgyjxQnOM1H/i8aoBZBjK7IbFnwf3 wsAyMOxce3FqzRxybu6PZja0YNoTaC6j7bgdbcyYCZVzdsH3CCkAMiqWshjDorwTpXni iLM2zMrsHr3i9mVT3Rx7dzcXmIwLsTxMS/EQOpOBljbbIMZ8pr+jUYQa74wC9Z7U17fD IZzw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=4mmXT6cz; 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=bytedance.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t3-20020aa7d4c3000000b004595af54eacsi14789870edr.226.2022.11.10.00.17.21; Thu, 10 Nov 2022 00:17:44 -0800 (PST) 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=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=4mmXT6cz; 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=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232548AbiKJIPx (ORCPT <rfc822;winker.wchi@gmail.com> + 99 others); Thu, 10 Nov 2022 03:15:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232515AbiKJIPr (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Thu, 10 Nov 2022 03:15:47 -0500 Received: from mail-pg1-x531.google.com (mail-pg1-x531.google.com [IPv6:2607:f8b0:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8731B1D4 for <linux-kernel@vger.kernel.org>; Thu, 10 Nov 2022 00:15:46 -0800 (PST) Received: by mail-pg1-x531.google.com with SMTP id f63so1098185pgc.2 for <linux-kernel@vger.kernel.org>; Thu, 10 Nov 2022 00:15:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=1JiyZ1hWVATL+iuWQbgLK9dDD8NJ+KjIJFMCcv1dNws=; b=4mmXT6czmfIGpWlJqlmQJ7kyF/U8tRAzRlYHJ596QLAPAp9RO1DzlieBk3D31YyM/d 39uaR6S/tt3G0VlYgbCVDLCPMfDTAF3l72d0FMLo4IvR5UYcvRdqOzNeB1aRq1pl/4DH OyDjLIpaYko5MopKW5xaUzHz3Psva0fk6QsuyJQFpv+UTMZocZMLcdMUuvNRMu/D9+md I+wfjbyBWBpsrKRjrBMHqykmNLdmmsNbtN245WNLTQU9eYqEa7XzaNFfxGsHkR9Sq36a d07BN6IVsrDIAxgwt5kXNWG3oQIs8pLJYB7wn4Jwa9shFAzrqJaxZCI4YtFCMOOYK59M Kl5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=1JiyZ1hWVATL+iuWQbgLK9dDD8NJ+KjIJFMCcv1dNws=; b=xQAt9Ll/IXQG+bR68nudItGLlLxMgEZPgESwt3YqiGDCg3INPjVUfpM8nQthfYeV6j 3Vs2onPhwaBxD+ZMZibc2BBDD0hNlHEs6JObWfT2x6cK8eTIkwSNrOBZCYoOcLznLGsk 7TMRc7eRl5Z0Hfb7sfK0xrUKd/NIkTH04Rc7R8YMJD3/Q6mmRWDPNbWr3cTSpahwEv59 UUGIapZdugjtcl2Q8pCgbVvN5qB5D7KstUEhrWMBeDrCCWLDdEvf/GE7xc0/jl30bYON tej6oc+yZ24GrTa5c4hbt1WYir9kZcI33DCu690XIM26uhAvr2rc/iuDnMaPHt+93uCs LlzA== X-Gm-Message-State: ACrzQf2nHObPkQSszE67WCUMaiF2mTZiurpWw5OwlTIfJ+c6OOkAgu3P Yl7IBf1ESwSnJivy56xZgYIqlM93QB1l0Q== X-Received: by 2002:a63:7d4f:0:b0:470:399:c953 with SMTP id m15-20020a637d4f000000b004700399c953mr1864613pgn.263.1668068146139; Thu, 10 Nov 2022 00:15:46 -0800 (PST) Received: from devtp.bytedance.net ([139.177.225.243]) by smtp.gmail.com with ESMTPSA id k5-20020a17090a7f0500b0020af2411721sm2496587pjl.34.2022.11.10.00.15.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Nov 2022 00:15:45 -0800 (PST) From: wuqiang <wuqiang.matt@bytedance.com> To: mhiramat@kernel.org, davem@davemloft.net, anil.s.keshavamurthy@intel.com, naveen.n.rao@linux.ibm.com Cc: solar@openwall.com, linux-kernel@vger.kernel.org, mattwu@163.com, wuqiang <wuqiang.matt@bytedance.com> Subject: [PATCH v2] kprobes: kretprobe events missing on 2-core KVM guest Date: Thu, 10 Nov 2022 16:15:02 +0800 Message-Id: <20221110081502.492289-1-wuqiang.matt@bytedance.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221026003315.266d59d5c0780c2817be3a0d@kernel.org> References: <20221026003315.266d59d5c0780c2817be3a0d@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,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?1749096348588884884?= X-GMAIL-MSGID: =?utf-8?q?1749096348588884884?= |
Series |
[v2] kprobes: kretprobe events missing on 2-core KVM guest
|
|
Commit Message
wuqiang.matt
Nov. 10, 2022, 8:15 a.m. UTC
Default value of maxactive is set as num_possible_cpus() for nonpreemptable
systems. For a 2-core system, only 2 kretprobe instances would be allocated
in default, then these 2 instances for execve kretprobe are very likely to
be used up with a pipelined command.
Here's the testcase: a shell script was added to crontab, and the content
of the script is:
#!/bin/sh
do_something_magic `tr -dc a-z < /dev/urandom | head -c 10`
cron will trigger a series of program executions (4 times every hour). Then
events loss would be noticed normally after 3-4 hours of testings.
The issue is caused by a burst of series of execve requests. The best number
of kretprobe instances could be different case by case, and should be user's
duty to determine, but num_possible_cpus() as the default value is inadequate
especially for systems with small number of cpus.
This patch enables the logic for preemption as default, thus increases the
minimum of maxactive to 10 for nonpreemptable systems.
Signed-off-by: wuqiang <wuqiang.matt@bytedance.com>
---
Documentation/trace/kprobes.rst | 3 +--
kernel/kprobes.c | 10 +++-------
2 files changed, 4 insertions(+), 9 deletions(-)
--
2.34.1
Comments
On Thu, Nov 10, 2022 at 04:15:02PM +0800, wuqiang wrote: > Default value of maxactive is set as num_possible_cpus() for nonpreemptable > systems. For a 2-core system, only 2 kretprobe instances would be allocated > in default, then these 2 instances for execve kretprobe are very likely to > be used up with a pipelined command. > > Here's the testcase: a shell script was added to crontab, and the content > of the script is: > > #!/bin/sh > do_something_magic `tr -dc a-z < /dev/urandom | head -c 10` > > cron will trigger a series of program executions (4 times every hour). Then > events loss would be noticed normally after 3-4 hours of testings. > > The issue is caused by a burst of series of execve requests. The best number > of kretprobe instances could be different case by case, and should be user's > duty to determine, but num_possible_cpus() as the default value is inadequate > especially for systems with small number of cpus. > > This patch enables the logic for preemption as default, thus increases the > minimum of maxactive to 10 for nonpreemptable systems. > > Signed-off-by: wuqiang <wuqiang.matt@bytedance.com> Reviewed-by: Solar Designer <solar@openwall.com> Thank you! > --- > Documentation/trace/kprobes.rst | 3 +-- > kernel/kprobes.c | 10 +++------- > 2 files changed, 4 insertions(+), 9 deletions(-) > > diff --git a/Documentation/trace/kprobes.rst b/Documentation/trace/kprobes.rst > index 48cf778a2468..fc7ce76eab65 100644 > --- a/Documentation/trace/kprobes.rst > +++ b/Documentation/trace/kprobes.rst > @@ -131,8 +131,7 @@ For example, if the function is non-recursive and is called with a > spinlock held, maxactive = 1 should be enough. If the function is > non-recursive and can never relinquish the CPU (e.g., via a semaphore > or preemption), NR_CPUS should be enough. If maxactive <= 0, it is > -set to a default value. If CONFIG_PREEMPT is enabled, the default > -is max(10, 2*NR_CPUS). Otherwise, the default is NR_CPUS. > +set to a default value: max(10, 2*NR_CPUS). > > It's not a disaster if you set maxactive too low; you'll just miss > some probes. In the kretprobe struct, the nmissed field is set to > diff --git a/kernel/kprobes.c b/kernel/kprobes.c > index a8b202f87e2d..1e80bddf2654 100644 > --- a/kernel/kprobes.c > +++ b/kernel/kprobes.c > @@ -2212,11 +2212,7 @@ int register_kretprobe(struct kretprobe *rp) > rp->kp.post_handler = NULL; > > /* Pre-allocate memory for max kretprobe instances */ > - if (rp->maxactive <= 0) { > -#ifdef CONFIG_PREEMPTION > + if (rp->maxactive <= 0) > rp->maxactive = max_t(unsigned int, 10, 2*num_possible_cpus()); > -#else > - rp->maxactive = num_possible_cpus(); > -#endif > - } > + > #ifdef CONFIG_KRETPROBE_ON_RETHOOK > -- > 2.34.1 Alexander
On Thu, 10 Nov 2022 15:52:23 +0100 Solar Designer <solar@openwall.com> wrote: > On Thu, Nov 10, 2022 at 04:15:02PM +0800, wuqiang wrote: > > Default value of maxactive is set as num_possible_cpus() for nonpreemptable > > systems. For a 2-core system, only 2 kretprobe instances would be allocated > > in default, then these 2 instances for execve kretprobe are very likely to > > be used up with a pipelined command. > > > > Here's the testcase: a shell script was added to crontab, and the content > > of the script is: > > > > #!/bin/sh > > do_something_magic `tr -dc a-z < /dev/urandom | head -c 10` > > > > cron will trigger a series of program executions (4 times every hour). Then > > events loss would be noticed normally after 3-4 hours of testings. > > > > The issue is caused by a burst of series of execve requests. The best number > > of kretprobe instances could be different case by case, and should be user's > > duty to determine, but num_possible_cpus() as the default value is inadequate > > especially for systems with small number of cpus. > > > > This patch enables the logic for preemption as default, thus increases the > > minimum of maxactive to 10 for nonpreemptable systems. Hm, OK. I think the enough value depends on where you put the probes on. But maybe just making it NR_CPU -> 2 * NR_CPUS is reasonable. Acked-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Thanks, > > > > Signed-off-by: wuqiang <wuqiang.matt@bytedance.com> > > Reviewed-by: Solar Designer <solar@openwall.com> > > Thank you! > > > --- > > Documentation/trace/kprobes.rst | 3 +-- > > kernel/kprobes.c | 10 +++------- > > 2 files changed, 4 insertions(+), 9 deletions(-) > > > > diff --git a/Documentation/trace/kprobes.rst b/Documentation/trace/kprobes.rst > > index 48cf778a2468..fc7ce76eab65 100644 > > --- a/Documentation/trace/kprobes.rst > > +++ b/Documentation/trace/kprobes.rst > > @@ -131,8 +131,7 @@ For example, if the function is non-recursive and is called with a > > spinlock held, maxactive = 1 should be enough. If the function is > > non-recursive and can never relinquish the CPU (e.g., via a semaphore > > or preemption), NR_CPUS should be enough. If maxactive <= 0, it is > > -set to a default value. If CONFIG_PREEMPT is enabled, the default > > -is max(10, 2*NR_CPUS). Otherwise, the default is NR_CPUS. > > +set to a default value: max(10, 2*NR_CPUS). > > > > It's not a disaster if you set maxactive too low; you'll just miss > > some probes. In the kretprobe struct, the nmissed field is set to > > diff --git a/kernel/kprobes.c b/kernel/kprobes.c > > index a8b202f87e2d..1e80bddf2654 100644 > > --- a/kernel/kprobes.c > > +++ b/kernel/kprobes.c > > @@ -2212,11 +2212,7 @@ int register_kretprobe(struct kretprobe *rp) > > rp->kp.post_handler = NULL; > > > > /* Pre-allocate memory for max kretprobe instances */ > > - if (rp->maxactive <= 0) { > > -#ifdef CONFIG_PREEMPTION > > + if (rp->maxactive <= 0) > > rp->maxactive = max_t(unsigned int, 10, 2*num_possible_cpus()); > > -#else > > - rp->maxactive = num_possible_cpus(); > > -#endif > > - } > > + > > #ifdef CONFIG_KRETPROBE_ON_RETHOOK > > -- > > 2.34.1 > > Alexander
diff --git a/Documentation/trace/kprobes.rst b/Documentation/trace/kprobes.rst index 48cf778a2468..fc7ce76eab65 100644 --- a/Documentation/trace/kprobes.rst +++ b/Documentation/trace/kprobes.rst @@ -131,8 +131,7 @@ For example, if the function is non-recursive and is called with a spinlock held, maxactive = 1 should be enough. If the function is non-recursive and can never relinquish the CPU (e.g., via a semaphore or preemption), NR_CPUS should be enough. If maxactive <= 0, it is -set to a default value. If CONFIG_PREEMPT is enabled, the default -is max(10, 2*NR_CPUS). Otherwise, the default is NR_CPUS. +set to a default value: max(10, 2*NR_CPUS). It's not a disaster if you set maxactive too low; you'll just miss some probes. In the kretprobe struct, the nmissed field is set to diff --git a/kernel/kprobes.c b/kernel/kprobes.c index a8b202f87e2d..1e80bddf2654 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -2212,11 +2212,7 @@ int register_kretprobe(struct kretprobe *rp) rp->kp.post_handler = NULL; /* Pre-allocate memory for max kretprobe instances */ - if (rp->maxactive <= 0) { -#ifdef CONFIG_PREEMPTION + if (rp->maxactive <= 0) rp->maxactive = max_t(unsigned int, 10, 2*num_possible_cpus()); -#else - rp->maxactive = num_possible_cpus(); -#endif - } + #ifdef CONFIG_KRETPROBE_ON_RETHOOK