Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1161505rwb; Thu, 6 Oct 2022 09:10:45 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4lW7A4nHU/t9p916E8pcpSOUkxklO73yMOErpqommZdF9an6Le/gxS/mYc/hfI6xRNlZbQ X-Received: by 2002:a17:907:2e0b:b0:78d:387d:1579 with SMTP id ig11-20020a1709072e0b00b0078d387d1579mr439147ejc.761.1665072645234; Thu, 06 Oct 2022 09:10:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665072645; cv=none; d=google.com; s=arc-20160816; b=HvGXFQtSJlC+5ZyYUgMQ6IVq45/KnvTHREBdKHujfwmw3DfnUPSwH16aimVHkIAJyw fE1N8RyUM+/oT6Fahp3WyYoCfgm477eBEBQs6POQ0sD+bT/oPbmjoPhS0Jpy1fWi75hM zMNg5pkSv+cwrrFgkwQhBTTpvbe/2ADzgcZhmuIkyL3i/5Pz2sJnhjLJXNvJpDmVqD1L gUCnly02DTBAnTEvvCf4EhGzvw8JVJ0QoFPtofKvIxo79r9h9O9Eb04bgb3MD5dakoqI BitoIs+gfohfDVkPTvNZf/s/sUouUcVSQ+vS/s6zQe+gQqpbetBzzN+dBY1Y3A7FL0z+ upVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=zm6xeXW0jCLbsA/duPDusxJlDbKzTuDSlIfxsNlzugc=; b=Jw6aXeKtvTMggzfl1fVcehQXYge2ISqdYJtIUZySVdg1Jo1rZZpGGSLOyAKGPCdLeY OcQBSNqoq3nKQdR69qs3r79bG0R+G2b7Tlv83nQIJA0LGJ+HKMwb5H0kfgGmyqJmO5/N +B2NeQ9FE+iPlqYZxwtpO3szgtj0Qqkiw2/fK37whNK46yz/OcVxBD8OFLad1oi3aa59 rq9ox4ddw9XSVSTlvYQbPw9qU8dBQYGZThzcerAkU2sM9t3VyF5tUIl1c7epZrmZspFL xclTY0qIaWhG1l/QMEoFLrPoplCkk/Jpx2NyOboFi95BzEyKguZTrzC0FqZOIvQws75A Vphg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=EOo9MOrs; 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 sh14-20020a1709076e8e00b00781a47397b1si16750968ejc.502.2022.10.06.09.10.15; Thu, 06 Oct 2022 09:10:45 -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=@infradead.org header.s=desiato.20200630 header.b=EOo9MOrs; 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 S231978AbiJFQDP (ORCPT + 99 others); Thu, 6 Oct 2022 12:03:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231976AbiJFQDM (ORCPT ); Thu, 6 Oct 2022 12:03:12 -0400 Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64FECABD47; Thu, 6 Oct 2022 09:03:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=zm6xeXW0jCLbsA/duPDusxJlDbKzTuDSlIfxsNlzugc=; b=EOo9MOrsq5fgau58Ph4wmN1PWq EknZ/8ivg7z3KXTpTrUHcnXW1aesXrgbIaX/FdJ/lwZ09KgrTtclp0/94wy0cAgW4kweUSnA1KnW8 Rt+iVdFAvqrmOvytcaJlHMZZxx0E0ZE3XpVniOakbvavlXnGtDbH/zk9YXb4SnGEcjm8T336dMX/1 h0sOmbnodCnBN4Uqq3h2d3+R5UA+/Aqxip+uLPzNO5FseocDzSAUKAnnQKQkqP24xevppN6NSL01b OYNjabvOxm+jsjaJp4FUfzCDlPG+XXHGNvTQcSQMrcbTF2P3rrVXb8YL7ZyUsIH9KB5hTbTaQvLvI 5bFwx8cw==; Received: from j130084.upc-j.chello.nl ([24.132.130.84] helo=noisy.programming.kicks-ass.net) by desiato.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1ogTKs-001GSf-9e; Thu, 06 Oct 2022 16:02:58 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 47397300137; Thu, 6 Oct 2022 18:02:57 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 0995220ACE696; Thu, 6 Oct 2022 18:02:57 +0200 (CEST) Date: Thu, 6 Oct 2022 18:02:56 +0200 From: Peter Zijlstra To: Marco Elver 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: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE 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, Oct 06, 2022 at 03:59:55PM +0200, Marco Elver wrote: > That one I could fix up with: > > | diff --git a/kernel/events/core.c b/kernel/events/core.c > | index 9319af6013f1..2f1d51b50be7 100644 > | --- a/kernel/events/core.c > | +++ b/kernel/events/core.c > | @@ -6563,6 +6563,7 @@ static void perf_pending_task(struct callback_head *head) > | * If we 'fail' here, that's OK, it means recursion is already disabled > | * and we won't recurse 'further'. > | */ > | + preempt_disable_notrace(); > | rctx = perf_swevent_get_recursion_context(); > | > | if (event->pending_work) { > | @@ -6573,6 +6574,7 @@ static void perf_pending_task(struct callback_head *head) > | > | if (rctx >= 0) > | perf_swevent_put_recursion_context(rctx); > | + preempt_enable_notrace(); > | } > | > | #ifdef CONFIG_GUEST_PERF_EVENTS Right, thanks! It appears I only have lockdep enabled but not the preempt warning :/ > But following that, I get: > > | WARNING: CPU: 3 PID: 13018 at kernel/events/core.c:2288 event_sched_out+0x3f2/0x410 kernel/events/core.c:2288 I'm taking this is (my line numbers are slightly different): WARN_ON_ONCE(event->pending_work); > So something isn't quite right yet. Unfortunately I don't have a good > reproducer. :-/ This can happen if we get two consecutive event_sched_out() and both instances will have pending_sigtrap set. This can happen when the event that has sigtrap set also triggers in kernel space. You then get task_work list corruption and *boom*. I'm thinking the below might be the simplest solution; we can only send a single signal after all. --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -2293,9 +2293,10 @@ event_sched_out(struct perf_event *event */ local_dec(&event->ctx->nr_pending); } else { - WARN_ON_ONCE(event->pending_work); - event->pending_work = 1; - task_work_add(current, &event->pending_task, TWA_RESUME); + if (!event->pending_work) { + event->pending_work = 1; + task_work_add(current, &event->pending_task, TWA_RESUME); + } } }