Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp788169rwb; Thu, 10 Nov 2022 07:26:26 -0800 (PST) X-Google-Smtp-Source: AMsMyM5VH1T0OWmfbgNLZ+FZMYq9lJMARsJpH3LyeMiMorUgj6HfGXFWu6o/K8ajEzyp7tifZolo X-Received: by 2002:a17:906:6898:b0:7ae:2ae6:f57e with SMTP id n24-20020a170906689800b007ae2ae6f57emr30469395ejr.126.1668093986217; Thu, 10 Nov 2022 07:26:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668093986; cv=none; d=google.com; s=arc-20160816; b=qUBpqvVswvJ2utlP0S9yprt1wcHb0VFteuF1P4B+FN9T52lvHFGhUFP0DXE0VGKpov hxnD/L+O42OGXUCW6vFi/9L2ALsRY85H27pm3IEZTEnfP5sdC9OpVFpGrZUE9yUecHvk Px8YCcBxPTZKjwNslC1E7b2kOlZnZOORIyxC/3Hpz0DEYy3UiZNeHPMcciwwxjtv3DbY tr5Dj1WPq7ZgPiHs0jpx+CK0tHzVKEQJ9dJqpUV2ylZ8bLf+HMYM8PnhovKliUgLFhx9 M/vA6alUEZluGwqT0ha2sTt3RE2GkOT/3KsNUfaz6ZKltux7ZH924g3+koh7qb1rzKBQ momw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=AxpWPyrJ6T2uLYH+PEj54fcXOheMCA4WMeJ6Thp6z98=; b=R168l+cBKiOoW49OSFPZzElB1Gf4NkGJ684GQYxY1+tkS60rOyxrmyU0MsMJyXp7lq KQvLQ2p7J29yI6IEDCDlYKWRL3qDJPK9WsyJy/iKRMeb6sR9FUKklwcD1n+i4DacMHRI sVEWa+K9goQUCarZKRvvOgV4TStG8peR1AiMopiyleXhna6w2iu/9uCb9z/RSDCKiZAq 9vyQ51BSkRRHy5YhNABKuct4eqwRKWNBPpeD5nJmAepR3e2BsgN3fjwCoHikeDC0kI3X cieR6vPBjg1uyN1LbYFc+iUYPE4r2TxFECNpfNSEbRMfT4GstGgIC0qNPXehnO18r0ao rulw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t10-20020a056402524a00b00457c9eddd10si21805333edd.617.2022.11.10.07.26.03; Thu, 10 Nov 2022 07:26:26 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229562AbiKJOwk (ORCPT + 92 others); Thu, 10 Nov 2022 09:52:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229478AbiKJOwi (ORCPT ); Thu, 10 Nov 2022 09:52:38 -0500 Received: from second.openwall.net (second.openwall.net [193.110.157.125]) by lindbergh.monkeyblade.net (Postfix) with SMTP id 53D1BFAD7 for ; Thu, 10 Nov 2022 06:52:34 -0800 (PST) Received: (qmail 18111 invoked from network); 10 Nov 2022 14:52:32 -0000 Received: from localhost (HELO pvt.openwall.com) (127.0.0.1) by localhost with SMTP; 10 Nov 2022 14:52:32 -0000 Received: by pvt.openwall.com (Postfix, from userid 503) id A17E0AB3A4; Thu, 10 Nov 2022 15:52:23 +0100 (CET) Date: Thu, 10 Nov 2022 15:52:23 +0100 From: Solar Designer To: wuqiang Cc: mhiramat@kernel.org, davem@davemloft.net, anil.s.keshavamurthy@intel.com, naveen.n.rao@linux.ibm.com, linux-kernel@vger.kernel.org, mattwu@163.com, Adam Zabrocki Subject: Re: [PATCH v2] kprobes: kretprobe events missing on 2-core KVM guest Message-ID: <20221110145223.GA14731@openwall.com> References: <20221026003315.266d59d5c0780c2817be3a0d@kernel.org> <20221110081502.492289-1-wuqiang.matt@bytedance.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20221110081502.492289-1-wuqiang.matt@bytedance.com> User-Agent: Mutt/1.4.2.3i X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_MSPIKE_H2, 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: X-Mailing-List: linux-kernel@vger.kernel.org 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 Reviewed-by: Solar Designer 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