Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp232621imw; Mon, 4 Jul 2022 08:14:19 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tC0enQ8fJrU7jtfM57Wkg4ZYQZK0z9+g73FmI9yRbLPTfGcVbm7EXgPBUXhiw7kAXcS1Hs X-Received: by 2002:a17:906:2088:b0:711:f512:837a with SMTP id 8-20020a170906208800b00711f512837amr29307303ejq.113.1656947659128; Mon, 04 Jul 2022 08:14:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656947659; cv=none; d=google.com; s=arc-20160816; b=ipsu7lYx/DO1M3UR9qukf2W7U+bbG12A7RAdRCzHCusFxXftQH7/bAn7C8ggSUMe8u omeLjRE4zZsP8GN1A8g7h0GBV5/KWd9+0CF1cveW1i2odN6R8Ul2u3nNN9T05lm1j/md vBTgmyvLK75NubDNOFaPrJoto6Fxmr2G0V8t77NebyJDoe7p0rS6kyAtoTCPzZeANnJj AgaTwdn9NqCbPzKEIdc128a6SBFJ8GVHhXdmx4le9NBOlQaTvZtbNn2TSwj7niMrrZGE vW/fHktwLLXuI/jsxG6DIs/fbgcvOnX+cltZx//EN76HZYUKAPhEQf9EXTb78m9aJ0WD LaRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=7hCwDytAsB4d/o82PG/imXl6AB+798LjkY2ZfHNBYrI=; b=L8bEyHNIb/sGT1VNPaQVpBYS6ArqqlYb0y8wWJn1k/9gno6M9M2rtO3XvmIVnQPPNc O2rr48hkSUOLhbdVV8ehlkgl/z9SuuAsjgQLQq0LFerGCUY0QYxeFdXj+b5wychs5pxa HRuK6Jn6/jApW1Rl5c8KpfbOs58sDHybr2cKZFi1msLXMsO/BrtV4gV5z7sRgGU0cBp9 C+N39ujcFaRHBeSHgMb2m9fFOmQaTsb/Wgn+Kj2QLnrfZEyJylHveVGbQY0gz3Du19vd z2QG/2v38mY13gIuUrj/E1yAQ1nRSinyyK89TUOpT+MXQKY33GFO/BVzo3t5ofqFeQdk UBdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="ThmQg/xx"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y2-20020aa7ce82000000b0043583452573si36874659edv.501.2022.07.04.08.13.53; Mon, 04 Jul 2022 08:14:19 -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=@google.com header.s=20210112 header.b="ThmQg/xx"; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234481AbiGDPKv (ORCPT + 99 others); Mon, 4 Jul 2022 11:10:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233963AbiGDPKg (ORCPT ); Mon, 4 Jul 2022 11:10:36 -0400 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9AE3AFD0C for ; Mon, 4 Jul 2022 08:09:55 -0700 (PDT) Received: by mail-lf1-x12d.google.com with SMTP id i18so16250681lfu.8 for ; Mon, 04 Jul 2022 08:09:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=7hCwDytAsB4d/o82PG/imXl6AB+798LjkY2ZfHNBYrI=; b=ThmQg/xxfdOOytGKZPYXFkjrB6rORV49rmwVnEzozNItIQovlnXYg1BPeS4b9eBnKn OuIGQ0fZkghqru/RvIC0zLh3jCDnd08wqc/mCaDkmdf8cUGR4xBtqHjEWYhfIVg06f7z T98O4cYhVvnA9/OHLuKcU2y2BnQrmbMlZ7TUsHxjTY+H4r2Hhzrl80a4N4BX4jnp6LNU 3rIzy4JWOXJ+YyA3DzaNFrxJVuxyM5a/VyWFQqRuRUhXvCg5BUJx+8FUIBki6xNxiOtN h/YMHmeXX5Nuz5rb+LXzAFWQwWU+I/zDKBYeTdJXvOA+gdWh5NJh6H3G2G2HUZvP7YfM rjVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=7hCwDytAsB4d/o82PG/imXl6AB+798LjkY2ZfHNBYrI=; b=QYMvJdDxXi+xNTX42HDvWGm+OARynQHTPWpAZoBWxa7cTP2N2o1Wjbdrlw7RLbiZL6 2ZCCeuc4y9KxOYMQ/zoGGmCaN8L9qF9+Nrj3+xRlmAHoHaF7oKsjYM202CHIjKruz3Mk 2kHDJA6FrDbNKjgA2y5tKfBU7OrA95bkotCN1In9mLrV0WMFaMnhZiSqQh9Exmc372GG iScwy7jH3bf7q/x/IENyO318jWDzbz/jT9OFe8GiaiwLe8gRxH8/tKuqr74rY79y0Dc6 zJkmF5ZL8SXuPlBkNm7XAj+CvFRAhWYz3NJ/uGUnXQ7ONHecb+vESyV0BgE5DUK3FWAU sBkQ== X-Gm-Message-State: AJIora9PCLjBNd+gCpyEFnph+2unHg24C7TfYsl7gJ6+2/LvfjZ9keCM WdkD3m4+0T8m+7fZyeebx9K7CpoUxKzkV8ebXSKxJw== X-Received: by 2002:a05:6512:1056:b0:47f:6f00:66c2 with SMTP id c22-20020a056512105600b0047f6f0066c2mr18349441lfb.410.1656947393715; Mon, 04 Jul 2022 08:09:53 -0700 (PDT) MIME-Version: 1.0 References: <20220704150514.48816-1-elver@google.com> <20220704150514.48816-3-elver@google.com> In-Reply-To: <20220704150514.48816-3-elver@google.com> From: Dmitry Vyukov Date: Mon, 4 Jul 2022 17:09:42 +0200 Message-ID: Subject: Re: [PATCH v3 02/14] perf/hw_breakpoint: Provide hw_breakpoint_is_used() and use in test To: Marco Elver Cc: Peter Zijlstra , Frederic Weisbecker , Ingo Molnar , Thomas Gleixner , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Michael Ellerman , linuxppc-dev@lists.ozlabs.org, linux-perf-users@vger.kernel.org, x86@kernel.org, linux-sh@vger.kernel.org, kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=unavailable 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 Mon, 4 Jul 2022 at 17:06, Marco Elver wrote: > > Provide hw_breakpoint_is_used() to check if breakpoints are in use on > the system. > > Use it in the KUnit test to verify the global state before and after a > test case. > > Signed-off-by: Marco Elver Reviewed-by: Dmitry Vyukov > --- > v3: > * New patch. > --- > include/linux/hw_breakpoint.h | 3 +++ > kernel/events/hw_breakpoint.c | 29 +++++++++++++++++++++++++++++ > kernel/events/hw_breakpoint_test.c | 12 +++++++++++- > 3 files changed, 43 insertions(+), 1 deletion(-) > > diff --git a/include/linux/hw_breakpoint.h b/include/linux/hw_breakpoint.h > index 78dd7035d1e5..a3fb846705eb 100644 > --- a/include/linux/hw_breakpoint.h > +++ b/include/linux/hw_breakpoint.h > @@ -74,6 +74,7 @@ register_wide_hw_breakpoint(struct perf_event_attr *attr, > extern int register_perf_hw_breakpoint(struct perf_event *bp); > extern void unregister_hw_breakpoint(struct perf_event *bp); > extern void unregister_wide_hw_breakpoint(struct perf_event * __percpu *cpu_events); > +extern bool hw_breakpoint_is_used(void); > > extern int dbg_reserve_bp_slot(struct perf_event *bp); > extern int dbg_release_bp_slot(struct perf_event *bp); > @@ -121,6 +122,8 @@ register_perf_hw_breakpoint(struct perf_event *bp) { return -ENOSYS; } > static inline void unregister_hw_breakpoint(struct perf_event *bp) { } > static inline void > unregister_wide_hw_breakpoint(struct perf_event * __percpu *cpu_events) { } > +static inline bool hw_breakpoint_is_used(void) { return false; } > + > static inline int > reserve_bp_slot(struct perf_event *bp) {return -ENOSYS; } > static inline void release_bp_slot(struct perf_event *bp) { } > diff --git a/kernel/events/hw_breakpoint.c b/kernel/events/hw_breakpoint.c > index f32320ac02fd..fd5cd1f9e7fc 100644 > --- a/kernel/events/hw_breakpoint.c > +++ b/kernel/events/hw_breakpoint.c > @@ -604,6 +604,35 @@ void unregister_wide_hw_breakpoint(struct perf_event * __percpu *cpu_events) > } > EXPORT_SYMBOL_GPL(unregister_wide_hw_breakpoint); > > +/** > + * hw_breakpoint_is_used - check if breakpoints are currently used > + * > + * Returns: true if breakpoints are used, false otherwise. > + */ > +bool hw_breakpoint_is_used(void) > +{ > + int cpu; > + > + if (!constraints_initialized) > + return false; > + > + for_each_possible_cpu(cpu) { > + for (int type = 0; type < TYPE_MAX; ++type) { > + struct bp_cpuinfo *info = get_bp_info(cpu, type); > + > + if (info->cpu_pinned) > + return true; > + > + for (int slot = 0; slot < nr_slots[type]; ++slot) { > + if (info->tsk_pinned[slot]) > + return true; > + } > + } > + } > + > + return false; > +} > + > static struct notifier_block hw_breakpoint_exceptions_nb = { > .notifier_call = hw_breakpoint_exceptions_notify, > /* we need to be notified first */ > diff --git a/kernel/events/hw_breakpoint_test.c b/kernel/events/hw_breakpoint_test.c > index 433c5c45e2a5..5ced822df788 100644 > --- a/kernel/events/hw_breakpoint_test.c > +++ b/kernel/events/hw_breakpoint_test.c > @@ -294,7 +294,14 @@ static struct kunit_case hw_breakpoint_test_cases[] = { > static int test_init(struct kunit *test) > { > /* Most test cases want 2 distinct CPUs. */ > - return num_online_cpus() < 2 ? -EINVAL : 0; > + if (num_online_cpus() < 2) > + return -EINVAL; > + > + /* Want the system to not use breakpoints elsewhere. */ > + if (hw_breakpoint_is_used()) > + return -EBUSY; > + > + return 0; > } > > static void test_exit(struct kunit *test) > @@ -308,6 +315,9 @@ static void test_exit(struct kunit *test) > kthread_stop(__other_task); > __other_task = NULL; > } > + > + /* Verify that internal state agrees that no breakpoints are in use. */ > + KUNIT_EXPECT_FALSE(test, hw_breakpoint_is_used()); > } > > static struct kunit_suite hw_breakpoint_test_suite = { > -- > 2.37.0.rc0.161.g10f37bed90-goog >