Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp2125041rwb; Sat, 8 Oct 2022 02:43:18 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5WsKiB/pnT4VWvKXkH+4kTUjbFgwv0mZmztTHY0qRYMJwBT1MOdRQ/3DvNWxAoVMVFVD1c X-Received: by 2002:aa7:d28c:0:b0:459:3cc5:3cb8 with SMTP id w12-20020aa7d28c000000b004593cc53cb8mr8542310edq.261.1665222198244; Sat, 08 Oct 2022 02:43:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665222198; cv=none; d=google.com; s=arc-20160816; b=iEzfo8unjw+3k5/ii0H9kpvkLcg/AwG0pKgyzLSFd+DA+7csw/WnN+PgrizQJ/nD7f x3byO6lrcGuCJv7Z230PpXRUFx97fRepLpXcd0/5jwwjBP15R4qmlXczK2LJ+decU6B7 bT6vhPyIe3YzpGccYwP70Yk7dGDDCbpoxI+E/reZVu6nPClfqOU8nioHIkiEA2bvtxWh NfeH/xfkClsBLO285RfEcNcAnJTvNOyvm9qfs28bPT/QrcjR+b1+kZzZNeaxmxU9s6gz EcRmIogp3FmCGa316yarE1iG1LHOtjJ1SiOb9TgPLpF9eBGxTxHiweM7q0bi6Uioebvj 1F1A== 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 :dkim-signature; bh=WxdcSrBOGO9MYgndz6qzjn61BZYNh2xTD3igd7MSm5c=; b=hc5d4jFM4lfPICvblUbNe/Vx8rgcANs0l8oM3yMhjNhE+pkC+AZzO3w1Mfp9kt9gYy DqN8YvtXYPi6PFWMJ2VNqu2uJlRhzK1vWwA0UBjL4P9/OX0UltZHhIkZFC+DDNKwXUZR F7NOn1s3cNp0pVwgBcWvojOjWfYz51A39enLdnuoYtyjTvLYcVMHkvKIiuzXegp4o8Zd P+44QONUE3+cO32MlXUaBbfFSZIYrYIgi2CbWAHIFI4dMj5Blhtk99s5J8Wrpg0DDDAt rrJQGXi5mBdz6kNbfQKGXjID4WkR6SLudimIptW71klD1ZQZycF9oojLA1crLR6BzXqD tRmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=nmR1Fi0P; 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 i17-20020a1709064fd100b007707b853e46si5479775ejw.882.2022.10.08.02.42.50; Sat, 08 Oct 2022 02:43:18 -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=nmR1Fi0P; 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 S229703AbiJHIlj (ORCPT + 99 others); Sat, 8 Oct 2022 04:41:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229539AbiJHIlh (ORCPT ); Sat, 8 Oct 2022 04:41:37 -0400 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5747410563 for ; Sat, 8 Oct 2022 01:41:36 -0700 (PDT) Received: by mail-ed1-x532.google.com with SMTP id w10so9825786edd.4 for ; Sat, 08 Oct 2022 01:41:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=WxdcSrBOGO9MYgndz6qzjn61BZYNh2xTD3igd7MSm5c=; b=nmR1Fi0PdzdMHZAyOKlzQqOUaEpdYIN8DD9ZEgkgrPLoFUPVTfpTAMOrdmKzL7MqBr /KKuy2dI5684FfSWWA4M7FAR9pTEM7kYYF433eJSYqOW8lb8h9y9LblCGzNUbrw9ppOi zCSNGlg1eZFhDFsKlrfvcIEeyILfI5ffIRPTPPsLR1HtC3ygkqrDyOUEttB7muWDmFCC dbPlF1uTHhHS75TJswE6JHGncNCbsvT4csytWCE5ekP2BmeIN8hUnaf+tj1F+iUNmx7S lghppvBIMQoKczZ4sT/fGAyB544J4u0R5R1CU3DEgmF6uIcMrGZ4yg9svwFNXvW9J0z2 V/+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=user-agent:in-reply-to:content-disposition:mime-version:references :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=WxdcSrBOGO9MYgndz6qzjn61BZYNh2xTD3igd7MSm5c=; b=3l79JoWww/spW1Zz0eTITkbageqTa94to0A8LbmdLMJrP7fF4Wg7npk/jZDTsB3cwj 3j+IKaWKZ63mjo9YOa8a6X6Q2iMqUoiTc6sI5iCr+kNg5N4/hunLvXWno/VRL+FfRXYp zEf04Qc9QHyZoX+dfruqtqUQCsfEgBZ3k69yNYGQ/v0dVF2+dLKz8kfFrkaE31BMNeHq 8Fbru5ZznVLJQSgg98eF1azsMRfyjxro8hKyBpBMrkVo95fYo9uN6fXBzvrWeIsxINh+ r97tAOlVhqAnoEawd7SRWMF/C+545tN15EDjPMNEocO5ej0oJTAfjaR/8EorQ5/L2skX VHMg== X-Gm-Message-State: ACrzQf3Vm4Mf5MH3RdbfvZxoDLOktITS6ezllDu3EnrABNqxxhKt4C4B qCxgVpfRH3O67UyIY+SV3lRKbg== X-Received: by 2002:a05:6402:1842:b0:458:e6f2:bd3d with SMTP id v2-20020a056402184200b00458e6f2bd3dmr7973061edy.169.1665218494605; Sat, 08 Oct 2022 01:41:34 -0700 (PDT) Received: from elver.google.com ([2a00:79e0:9c:201:6029:e851:8078:4621]) by smtp.gmail.com with ESMTPSA id d6-20020a50f686000000b00459e3a3f3ddsm3081688edn.79.2022.10.08.01.41.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Oct 2022 01:41:33 -0700 (PDT) Date: Sat, 8 Oct 2022 10:41:28 +0200 From: Marco Elver To: Peter Zijlstra Cc: Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, Dmitry Vyukov Subject: Re: [PATCH] perf: Fix missing SIGTRAPs Message-ID: References: <20220927121322.1236730-1-elver@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/2.2.7 (2022-08-07) 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, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 Fri, Oct 07, 2022 at 06:14PM +0200, Marco Elver wrote: > On Fri, Oct 07, 2022 at 03:58PM +0200, Marco Elver wrote: > > On Fri, Oct 07, 2022 at 03:09PM +0200, Peter Zijlstra wrote: > > > On Fri, Oct 07, 2022 at 11:37:34AM +0200, Marco Elver wrote: > > > > > > > That worked. In addition I had to disable the ctx->task != current check > > > > if we're in task_work, because presumably the event might have already > > > > been disabled/moved?? > > > > > > Uhmmm... uhhh... damn. (wall-time was significantly longer) > > > > > > Does this help? > > > > No unfortunately - still see: > > > > [ 82.300827] ------------[ cut here ]------------ > > [ 82.301680] WARNING: CPU: 0 PID: 976 at kernel/events/core.c:6466 perf_sigtrap+0x60/0x70 > > Whenever the warning fires, I see that event->state is OFF. The below patch to the sigtrap_threads test can repro the issue (when run lots of them concurrently again). It also illustrates the original problem we're trying to solve, where the event never gets rearmed again and the test times out (doesn't happen with the almost-working fix). Thanks, -- Marco ------ >8 ------ From 98d225bda6d94dd793a1d0c77ae4b301c364166e Mon Sep 17 00:00:00 2001 From: Marco Elver Date: Sat, 8 Oct 2022 10:26:58 +0200 Subject: [PATCH] selftests/perf_events: Add a SIGTRAP stress test with disables Add a SIGTRAP stress test that exercises repeatedly enabling/disabling an event while it concurrently keeps firing. Signed-off-by: Marco Elver --- .../selftests/perf_events/sigtrap_threads.c | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/perf_events/sigtrap_threads.c b/tools/testing/selftests/perf_events/sigtrap_threads.c index 6d849dc2bee0..d1d8483ac628 100644 --- a/tools/testing/selftests/perf_events/sigtrap_threads.c +++ b/tools/testing/selftests/perf_events/sigtrap_threads.c @@ -62,6 +62,8 @@ static struct perf_event_attr make_event_attr(bool enabled, volatile void *addr, .remove_on_exec = 1, /* Required by sigtrap. */ .sigtrap = 1, /* Request synchronous SIGTRAP on event. */ .sig_data = TEST_SIG_DATA(addr, id), + .exclude_kernel = 1, /* To allow */ + .exclude_hv = 1, /* running as !root */ }; return attr; } @@ -93,9 +95,13 @@ static void *test_thread(void *arg) __atomic_fetch_add(&ctx.tids_want_signal, tid, __ATOMIC_RELAXED); iter = ctx.iterate_on; /* read */ - for (i = 0; i < iter - 1; i++) { - __atomic_fetch_add(&ctx.tids_want_signal, tid, __ATOMIC_RELAXED); - ctx.iterate_on = iter; /* idempotent write */ + if (iter >= 0) { + for (i = 0; i < iter - 1; i++) { + __atomic_fetch_add(&ctx.tids_want_signal, tid, __ATOMIC_RELAXED); + ctx.iterate_on = iter; /* idempotent write */ + } + } else { + while (ctx.iterate_on); } return NULL; @@ -208,4 +214,27 @@ TEST_F(sigtrap_threads, signal_stress) EXPECT_EQ(ctx.first_siginfo.si_perf_data, TEST_SIG_DATA(&ctx.iterate_on, 0)); } +TEST_F(sigtrap_threads, signal_stress_with_disable) +{ + const int target_count = NUM_THREADS * 3000; + int i; + + ctx.iterate_on = -1; + + EXPECT_EQ(ioctl(self->fd, PERF_EVENT_IOC_ENABLE, 0), 0); + pthread_barrier_wait(&self->barrier); + while (__atomic_load_n(&ctx.signal_count, __ATOMIC_RELAXED) < target_count) { + EXPECT_EQ(ioctl(self->fd, PERF_EVENT_IOC_DISABLE, 0), 0); + EXPECT_EQ(ioctl(self->fd, PERF_EVENT_IOC_ENABLE, 0), 0); + } + ctx.iterate_on = 0; + for (i = 0; i < NUM_THREADS; i++) + ASSERT_EQ(pthread_join(self->threads[i], NULL), 0); + EXPECT_EQ(ioctl(self->fd, PERF_EVENT_IOC_DISABLE, 0), 0); + + EXPECT_EQ(ctx.first_siginfo.si_addr, &ctx.iterate_on); + EXPECT_EQ(ctx.first_siginfo.si_perf_type, PERF_TYPE_BREAKPOINT); + EXPECT_EQ(ctx.first_siginfo.si_perf_data, TEST_SIG_DATA(&ctx.iterate_on, 0)); +} + TEST_HARNESS_MAIN -- 2.38.0.rc1.362.ged0d419d3c-goog