Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp1946455lqe; Tue, 9 Apr 2024 05:37:02 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVXS7+YwdZzPdqqxbd/MVSaIKq77Otz5iC3fC9XEXOvF16HjsjD8YH5YSuUpJ1nECDYS/xqbWAYEubEMAGlZWT2OwVuJFQ4aYGQ0J7Jlw== X-Google-Smtp-Source: AGHT+IG4V1o7/lD8PNdONJg5UvPP+DH5yqpx+mC3dfbJVk7mfYXdjlq5RmTWRQE+aXL3q0vxXsJz X-Received: by 2002:a17:906:aec9:b0:a4e:67c9:8047 with SMTP id me9-20020a170906aec900b00a4e67c98047mr7133139ejb.32.1712666222475; Tue, 09 Apr 2024 05:37:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712666222; cv=pass; d=google.com; s=arc-20160816; b=t6aYBbOIncNoCdwEY+qZgeYj+C32mHo5ululUHx2fHah5+y9d1HB27mObnVqUE4dhj sIQnmEIb9eS73EjG7GW6dKPhD+ipOinTpJdkdCXeQi0kbezPyX2uyTkEsNdP0WxwKaPD 8WRpyeE3geEMshPZ2kVTave3uV7lYftILWPoZxB9eQw0YoBYdRG9ZjXim+IKi6JtElGD yWy+yvjT8XtCDswsJ7tulTRodctUEX4ihVEdfrMnrc8mljY1jajRaadqvvrVqFeA2NqO gQxc4kz5zdgruaIoPTvgrLfQFThE/RjXfLnirOfrLSCSIBTbfKPcG3lGZNqRyk5z2GnV oANQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date:dkim-signature; bh=jVzierGpNiC13kiGZPv0nnDyxAjipc8yLMN1lEuDY5w=; fh=tWedduKdZfmc5x5dPveXf04NtuTwlscpi5X/WE4lpxw=; b=IOoPLqq1kxgir2sAWdjLiFVE12ciO3W5JiHxWgpJfobTKnIWB6TEefG9Na1WPEsrnq 5KDslUKbRJBuYAIsxyyQDBQK47bZn45k+Mk3Rd+vhcoYllFgvybb7X7w/gKrDGEaSnf9 Bbt52n5AYHSJ5y2iNMk+qMzlmWDCbks6rZJ3IGoA1A5N6g2odOXq4z9fgT55YOOnB9so Y1sKMcpCPdqqXNjWHSLb+9Kz2e8HgqPKGM4VrpvrCUson3ZSN1W/M3zXwAJgxvaDiziw NzDXr6t+FzSACszN1IDIUjYec5+IeygNsxP6HHVN9VpypZF51sx16gEjtvQvskMCzOwy b5Vw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Qit/Rphu"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-136875-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-136875-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id w15-20020a17090633cf00b00a4422dcbc2bsi4599617eja.774.2024.04.09.05.37.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Apr 2024 05:37:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-136875-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Qit/Rphu"; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-136875-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-136875-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 337011F22A4D for ; Tue, 9 Apr 2024 12:37:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3671A12D753; Tue, 9 Apr 2024 12:36:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Qit/Rphu" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B97C22318; Tue, 9 Apr 2024 12:36:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712666214; cv=none; b=JoB8JeG2OEfVQ9ioCRyT61XiWC9+DzmZOyXBTgoMoOhxv1d3gjAZDiVeMuJAk/CryINyhgZH3Df2QCYZOLAf1vVl7QEe5peqTJEHCLMWMgxo1rkkJ5Q17ADr2t0DiO6RUxogoF8ujV+XIzUb0cKGB67fMhGhMJJuCAxtQCWm35I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712666214; c=relaxed/simple; bh=PCvyTmJFSBw/wF40SXFhkTfbKGm+lHZssDURb5RxCoU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=BoGwBFscXKmGUVRkMDZNRlsMs/Hs8kVgSy07fc1gAUeydubmkOAzZh/wl0FByFg3S+lukZyujG5NGtwQZ9ja2ra8+ECC7gTry9Zkio0ZjvuZjWIrpfYvoVCOMsH+jB935FoqHQF3A63rT+L2+B4FFygMu+ywA9bZRufyBxL08Xg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Qit/Rphu; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8A15CC433F1; Tue, 9 Apr 2024 12:36:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712666213; bh=PCvyTmJFSBw/wF40SXFhkTfbKGm+lHZssDURb5RxCoU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Qit/RphuZykfOHrkij6ZIkv1Qecy6nLHuhMx7XEMF51KTWC+HGbppgU0AK8gFBBaN MEHQ97xUdN4r7yJoGgnwXx35nhSOoL2FCFLz8BXBRuLanxXq0RHdTslAH4V9kONz/P GqyMDdRiXBepBE9VikefvML5XxetOrB4Y7TbdcD2T/G8S8WMT1fgUwL4dRXMgl9oz/ Rg/8StVaH7BdVBsHKYdodOYbHC7Y8HBqZzt8451ISYjNgBH7mse3NC7mYgEh0zxr7D 5Lt8XyU9geBjz4IFMZfUHkpXlKUrldyWDzzPAk34F4OtUnjkIEuVNswDgcMQv7WYtV a/ZVFNmYVdDwA== Date: Tue, 9 Apr 2024 14:36:51 +0200 From: Frederic Weisbecker To: Sebastian Andrzej Siewior Cc: linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, Adrian Hunter , Alexander Shishkin , Arnaldo Carvalho de Melo , Ian Rogers , Ingo Molnar , Jiri Olsa , Marco Elver , Mark Rutland , Namhyung Kim , Peter Zijlstra , Thomas Gleixner , Arnaldo Carvalho de Melo Subject: Re: [PATCH v3 2/4] perf: Enqueue SIGTRAP always via task_work. Message-ID: References: <20240322065208.60456-1-bigeasy@linutronix.de> <20240322065208.60456-3-bigeasy@linutronix.de> <20240409085732.FBItbOSO@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20240409085732.FBItbOSO@linutronix.de> Le Tue, Apr 09, 2024 at 10:57:32AM +0200, Sebastian Andrzej Siewior a écrit : > > > static void > > > perf_event_exit_event(struct perf_event *event, struct perf_event_context *ctx) > > > { > > > @@ -13088,6 +13084,18 @@ perf_event_exit_event(struct perf_event *event, struct perf_event_context *ctx) > > > * Kick perf_poll() for is_event_hup(); > > > */ > > > perf_event_wakeup(parent_event); > > > + /* > > > + * Cancel pending task_work and update counters if it has not > > > + * yet been delivered to userland. free_event() expects the > > > + * reference counter at one and keeping the event around until > > > + * the task returns to userland can be a unexpected if there is > > > + * no signal handler registered. > > > + */ > > > + if (event->pending_work && > > > + task_work_cancel_match(current, task_work_cb_match, event)) { > > > + put_event(event); > > > + local_dec(&event->ctx->nr_pending); > > > + } > > > > So exiting task, privileged exec and also exit on exec call into this before > > releasing the children. > > > > And parents rely on put_event() from file close + the task work. > > > > But what about remote release of children on file close? > > See perf_event_release_kernel() directly calling free_event() on them. > > Interesting things you are presenting. I had events popping up at random > even after the task decided that it won't go back to userland to handle > it so letting it free looked like the only option… > > > One possible fix is to avoid the reference count game around task work > > and flush them on free_event(). > > > > See here: > > > > https://lore.kernel.org/all/202403310406.TPrIela8-lkp@intel.com/T/#m63c28147d8ac06b21c64d7784d49f892e06c0e50 > > That wake_up() within preempt_disable() section breaks on RT. Ah, but the wake-up still wants to go inside recursion protection somehow or it could generate task_work loop again due to tracepoint events... Although... the wake up occurs only when the event is dead after all... > How do we go on from here? I'd tend to think you need my patchset first because the problems it fixes were not easily visible as long as there was an irq work to take care of things most of the time. But once you rely on task_work only then these become a real problem. Especially the sync against perf_release(). Thanks. > > > Thanks. > > Sebastian