From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) (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 2F43B1F76D5 for ; Fri, 17 Jan 2025 08:37:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=90.155.50.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737103026; cv=none; b=IGLY5j/IaGw8WEQxMZvCXJdOHnR0nHlFuuibXiN/WEk2Oo0vmdSUBITFo+P9dXgSiVc1ah642lb5xIYT9ZDTNk9CReIAKQ/ex8fgh2EgusIt4QV/wP2elOIfKiI7+pF2YIXm1ixHnQ6BpzdLzHNb/cLo7ZX6yq9pRujLR6/oPR8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737103026; c=relaxed/simple; bh=MofBHFScp/88q2wZNJXjND2rdQqWpCSuoja8PeKgQtg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Jm3RW6cO/t77EwC+N3RC3qJw/5WW5cmZ5ym2RtSej112f2SknoCjbdXuQ/dn8z3LOmdZL5Ex1OrsQCC1PY0qhjonWinFiCL50O20s2GtRRoP47AbDOMEeSD/3rjzo63q+bMdFeM8V2qXzzu3OwL72lvG1/DzgoZp4+hWLcimdIw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org; spf=none smtp.mailfrom=infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=LhKxCdGo; arc=none smtp.client-ip=90.155.50.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=infradead.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="LhKxCdGo" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; 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=sKWs7fcmFzOpfo3znJnZpFMR5i+S4gt2TfXB1lQp0oY=; b=LhKxCdGoyVOk8A4x8RoTw6yNKu RLIztNP7ZCEOD0U8xaB2O2I80YNj0Zo2ylDSZHIJ3wqt0Q8nkr1wiBJVCx0+5NZCSyko5a6c0UGCv EEhgE7Oa5xGxzVAgMMzaYoTwK62zfMjWXmmFrvDGU3hdLL4UYpHW6pM9APLATDQdth9bm/p0Yq8aQ /mZ+YE4y3o672MPH0Skw/BiurXsZTuK8+vOyfxktcmC5kAWyJKHDvVWOj7VtqPucULyr37uyag+/q FBFszWpsOw2ZRdzPiPwsizCNgXHGAG0qlhilOVoSjZILYOV0YioJzmkkEvRMYZlamSAi8T1LZDbId dPse3yTQ==; Received: from 77-249-17-89.cable.dynamic.v4.ziggo.nl ([77.249.17.89] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1tYhqc-0000000ASZy-3y9W; Fri, 17 Jan 2025 08:36:59 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id DCD5C30057A; Fri, 17 Jan 2025 09:36:57 +0100 (CET) Date: Fri, 17 Jan 2025 09:36:57 +0100 From: Peter Zijlstra To: Ravi Bangoria Cc: "mingo@kernel.org" , "lucas.demarchi@intel.com" , "linux-kernel@vger.kernel.org" , "willy@infradead.org" , "acme@kernel.org" , "namhyung@kernel.org" , "mark.rutland@arm.com" , "alexander.shishkin@linux.intel.com" , "jolsa@kernel.org" , "irogers@google.com" , "adrian.hunter@intel.com" , "kan.liang@linux.intel.com" Subject: Re: [PATCH 19/19] perf: Make perf_pmu_unregister() useable Message-ID: <20250117083657.GL8362@noisy.programming.kicks-ass.net> References: <20241104133909.669111662@infradead.org> <20241104135519.715883982@infradead.org> <20241217091216.GK35539@noisy.programming.kicks-ass.net> <20241217115219.GH12500@noisy.programming.kicks-ass.net> <8c31f7bd-871d-4a38-ad15-a16a116e1f39@amd.com> <20250117000316.GB33629@noisy.programming.kicks-ass.net> <795d9f60-73c8-48da-87a4-6336c170b388@amd.com> 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=us-ascii Content-Disposition: inline In-Reply-To: <795d9f60-73c8-48da-87a4-6336c170b388@amd.com> On Fri, Jan 17, 2025 at 10:50:26AM +0530, Ravi Bangoria wrote: > Hi Peter, > > >> 4) A race with perf_event_set_bpf_prog(). perf_event_set_bpf_prog() might > >> be in process of setting event->prog, where as perf_pmu_unregister(), > >> which internally calls perf_event_free_bpf_prog(), will clear the > >> event->prog pointer. > >> > >> perf_pmu_unregister() perf_event_set_bpf_prog() > >> ... perf_event_set_bpf_handler() > >> perf_event_free_bpf_prog() event->prog = prog; > >> event->prog = NULL; > >> > >> I've yet to inspect other code paths, so there might be more races. > > > > Weird, that should be serialized by perf_event_ctx_lock(), both > > __pmu_detach_event() and _perf_ioctl() are called under that. > > There are multiple code paths leading to perf_event_set_bpf_prog(). The > one starting from _perf_ioctl() is serialized. However, this is not: > > __sys_bpf() > link_create() > bpf_perf_link_attach() > perf_event_set_bpf_prog() > perf_event_set_bpf_handler() > event->prog = prog; > Urgh yeah, that's broken. Damn bpf stuff :-/