From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753536AbcAVMMg (ORCPT ); Fri, 22 Jan 2016 07:12:36 -0500 Received: from bombadil.infradead.org ([198.137.202.9]:41744 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753191AbcAVMM2 (ORCPT ); Fri, 22 Jan 2016 07:12:28 -0500 Date: Fri, 22 Jan 2016 13:12:22 +0100 From: Peter Zijlstra To: Alexander Shishkin Cc: Ingo Molnar , linux-kernel@vger.kernel.org, vince@deater.net, eranian@google.com, Arnaldo Carvalho de Melo , Jiri Olsa , alexei.starovoitov@gmail.com Subject: Re: [PATCH v2] perf: Synchronously cleanup child events Message-ID: <20160122121222.GR6357@twins.programming.kicks-ass.net> References: <20160118144410.GS6357@twins.programming.kicks-ass.net> <1453216354-9282-1-git-send-email-alexander.shishkin@linux.intel.com> <20160119200558.GC6357@twins.programming.kicks-ass.net> <87lh7hhmnn.fsf@ashishki-desk.ger.corp.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87lh7hhmnn.fsf@ashishki-desk.ger.corp.intel.com> User-Agent: Mutt/1.5.21 (2012-12-30) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 22, 2016 at 01:35:40PM +0200, Alexander Shishkin wrote: > Peter Zijlstra writes: > > > So I think there's a number of problems still :-( > > Also, it does indeed race with > __perf_event_exit_task()/sync_child_event(), but that one I'd fix by > simply wrapping the sync_child_event()/free_event() in > > mutex_lock(&parent_event->child_mutex); > if (!is_orphan_event(parent_event)) { > sync_child_event(child_event); > free_event(child_event); > } > mutex_unlock(&parent_event->child_event); So I've been staring at exactly that code for a while because Ingo managed to trigger that race (and I could reproduce with his 'workload'). But I'm not seeing how; both sites hold ctx->mutex and remove the event from the ctx->event_list. So the way I'm seeing it, either the orphan_work find and frees it, or the __perf_event_exit_task() one does, but I'm a bit stumped on how they can both do. Sure, the sync stuff is pointless if we're orphan, but I don't see how it can harm. > At some later point in time the code there could use a bit of > reshuffling, I guess. Yes.