From patchwork Tue Nov 8 15:49:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 17111 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2790038wru; Tue, 8 Nov 2022 07:51:02 -0800 (PST) X-Google-Smtp-Source: AMsMyM4YTCqOH+3fX3SC4ErGVu6twY2SlZc+l7JvEPGqQu/VeKXg0JlHnuxixemHbwc6KpjBvMNN X-Received: by 2002:a17:906:444d:b0:7ad:eb7f:8697 with SMTP id i13-20020a170906444d00b007adeb7f8697mr36521628ejp.770.1667922662024; Tue, 08 Nov 2022 07:51:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667922662; cv=none; d=google.com; s=arc-20160816; b=B2UAbmQV7SZEoGbryGRqQ1ro9Ap/51HyvKG04UaFZT7yRnDsY/W6gySk7zod23Vjfy ZsGOyp0N6DaAD8tAqbp+gfKiNLZ+EqdxCq0O4GMB9o2PuD0PFE8GF4zykKvubsV3Q0gs EoQIccR1HWI83uwfeZPEdGqRHTGTWZBFVoVzYh9GCjze6m9MsosKjCQ+3rGW9MWThBBF 448U07v0icvhxtqWqVR+DngGCpCvPPYDvnVXRIEaHvMwkGcp64oVDgMNT7KcnxUhBaks dDOV22fU2lvq63up5eW48x0F5Q5YIIOjzW+ELTVcWe/o+dTeR+hVrM0Rj8zr1mzDJ6Om hVEQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=bnwtxv94kpFRRs/ijDiWd71Pp+DTWIN+th+HeMQnsYs=; b=pbRw7aujC+RoxBF65XV19KxlkAECH1S0slk5JuWdvQZvhuyAhQpSFlPya21iqevuQv J907fXAy2RtBeLSq+Fq3Hm04aCfnj1DfoF7K+k5Kpqwh/xecs8T1/eHAT5Z1Uh2qEs6V pHgIUUWDD4GizghflvkOV3KOBQgZMgFUVZ+1k5soPbp6g60aqMki5zeBzpVv8GPw/lUC 8ON19OOWKaIsXpIgNqAckjPmRX2Gpm90eGXBjfUoaqMzRlV/ec9yhgJ2KyJ58S88vntZ jftQhQ+WyHhWtrHNHhs18ezNZiizdiX7lGutDSjPQmeHLeNIXyT+YVZCg81oIdWOme/m Pouw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=U8FmuCdM; 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=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g13-20020aa7c58d000000b0046437459191si11638648edq.476.2022.11.08.07.50.36; Tue, 08 Nov 2022 07:51:02 -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=@kernel.org header.s=k20201202 header.b=U8FmuCdM; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234493AbiKHPuH (ORCPT + 99 others); Tue, 8 Nov 2022 10:50:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234532AbiKHPt5 (ORCPT ); Tue, 8 Nov 2022 10:49:57 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A11645C764; Tue, 8 Nov 2022 07:49:56 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 1D2F7CE1BD9; Tue, 8 Nov 2022 15:49:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1AE6AC433D6; Tue, 8 Nov 2022 15:49:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667922593; bh=F/6mNWeMxsAl5sO9bPrQ/z7sSueL8mpIe+JI9wyTpYI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=U8FmuCdMpK+lpMhQo9J82CHO7rwMk1BCa7U0M97ydkONfEyQEEyVVpxw4oSF+EgPK yKv6X0HxVdO+8VeIRCG1fWqO+MaQsTAVxBDt7HTRWsAg7iVWw1UX86cgLng8RY1YrY aOzQxaQ/I3sKuBojHDCq7T3Yvk8cAj3YrOai2l5mK6mFZV+yZj5hXpKOAfYbK4IsSC 8U15dj5bTc1ehQVQlVBNHWbzUod08f//omP9ZKLjJuwtHPcP6qBg9ATuRGdk8+5n1O ycPdUV4siXqESznuqvTwSmcEG7tmcKJkhRQ1qdzLRuJ77VTtqwLG/ffMUTWDnXdnpS 1ucBLdHPd4q9w== From: "Masami Hiramatsu (Google)" To: linux-trace-kernel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Steven Rostedt , mhiramat@kernel.org, Florent Revest , Mark Rutland , Will Deacon Subject: [RFC PATCH 4/9] lib/test_fprobe: Add a test case for nr_maxactive Date: Wed, 9 Nov 2022 00:49:49 +0900 Message-Id: <166792258988.919356.1550112303992706866.stgit@devnote3> X-Mailer: git-send-email 2.38.1.431.g37b22c650d-goog In-Reply-To: <166792255429.919356.14116090269057513181.stgit@devnote3> References: <166792255429.919356.14116090269057513181.stgit@devnote3> User-Agent: StGit/0.19 MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748943673420062400?= X-GMAIL-MSGID: =?utf-8?q?1748943673420062400?= From: Masami Hiramatsu (Google) Add a test case for nr_maxactive. If the number of active functions is more than nr_maxactive, it must be skipped. Signed-off-by: Masami Hiramatsu (Google) --- lib/test_fprobe.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/lib/test_fprobe.c b/lib/test_fprobe.c index 941bf5234c31..976fb3f7cb01 100644 --- a/lib/test_fprobe.c +++ b/lib/test_fprobe.c @@ -17,8 +17,10 @@ static u32 rand1, entry_val, exit_val; /* Use indirect calls to avoid inlining the target functions */ static u32 (*target)(u32 value); static u32 (*target2)(u32 value); +static u32 (*target_nest)(u32 value, u32 (*nest)(u32)); static unsigned long target_ip; static unsigned long target2_ip; +static unsigned long target_nest_ip; static noinline u32 fprobe_selftest_target(u32 value) { @@ -30,6 +32,11 @@ static noinline u32 fprobe_selftest_target2(u32 value) return (value / div_factor) + 1; } +static noinline u32 fprobe_selftest_nest_target(u32 value, u32 (*nest)(u32)) +{ + return nest(value + 2); +} + static notrace void fp_entry_handler(struct fprobe *fp, unsigned long ip, struct pt_regs *regs, void *data) { @@ -67,6 +74,19 @@ static notrace void fp_exit_handler(struct fprobe *fp, unsigned long ip, KUNIT_EXPECT_NULL(current_test, data); } +static notrace void nest_entry_handler(struct fprobe *fp, unsigned long ip, + struct pt_regs *regs, void *data) +{ + KUNIT_EXPECT_FALSE(current_test, preemptible()); +} + +static notrace void nest_exit_handler(struct fprobe *fp, unsigned long ip, + struct pt_regs *regs, void *data) +{ + KUNIT_EXPECT_FALSE(current_test, preemptible()); + KUNIT_EXPECT_EQ(current_test, ip, target_nest_ip); +} + /* Test entry only (no rethook) */ static void test_fprobe_entry(struct kunit *test) { @@ -163,6 +183,25 @@ static void test_fprobe_data(struct kunit *test) KUNIT_EXPECT_EQ(test, 0, unregister_fprobe(&fp)); } +/* Test nr_maxactive */ +static void test_fprobe_nest(struct kunit *test) +{ + static const char *syms[] = {"fprobe_selftest_target", "fprobe_selftest_nest_target"}; + struct fprobe fp = { + .entry_handler = nest_entry_handler, + .exit_handler = nest_exit_handler, + .nr_maxactive = 1, + }; + + current_test = test; + KUNIT_EXPECT_EQ(test, 0, register_fprobe_syms(&fp, syms, 2)); + + target_nest(rand1, target); + KUNIT_EXPECT_EQ(test, 1, fp.nmissed); + + KUNIT_EXPECT_EQ(test, 0, unregister_fprobe(&fp)); +} + static unsigned long get_ftrace_location(void *func) { unsigned long size, addr = (unsigned long)func; @@ -181,8 +220,10 @@ static int fprobe_test_init(struct kunit *test) target = fprobe_selftest_target; target2 = fprobe_selftest_target2; + target_nest = fprobe_selftest_nest_target; target_ip = get_ftrace_location(target); target2_ip = get_ftrace_location(target2); + target_nest_ip = get_ftrace_location(target_nest); return 0; } @@ -192,6 +233,7 @@ static struct kunit_case fprobe_testcases[] = { KUNIT_CASE(test_fprobe), KUNIT_CASE(test_fprobe_syms), KUNIT_CASE(test_fprobe_data), + KUNIT_CASE(test_fprobe_nest), {} };