Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp2887861rwe; Mon, 29 Aug 2022 01:59:20 -0700 (PDT) X-Google-Smtp-Source: AA6agR5TfsEFlvv4SvynreCKuYaMScvqrH0NsaKPJmyngymxtV0rSeLOdhPuCVimwfYUeeJkTeju X-Received: by 2002:a05:6a00:130c:b0:535:ca9b:13e0 with SMTP id j12-20020a056a00130c00b00535ca9b13e0mr15576433pfu.55.1661763559854; Mon, 29 Aug 2022 01:59:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661763559; cv=none; d=google.com; s=arc-20160816; b=tc/ZspV9E/qws0pJDbwHn5AZ6pNmYbuGdl48d5WMwDpJY3EIS2Wer9sIfWQmRpuU74 4HulLSCSmCsdpqbNLFf0v9KUi7GOI0Hv7pqcfwpPE5KGLrdAkK/4ODJ3GiWmjRIZ/j1U 9Ekiv7xceZiVP0ebLRM89cg0OnODrg9KHnpmy4rGLob2WL/h2Eeea2FFiHFPxjpBBrZf iYxP0Oh4Hz7w5dp9UZ9hCGI/BLMPAWZ7R7g0U3qg4UeXCgpj6nL50jVjDrNXnj1LgtEa SMe7Ax1VpGzT7CylEHbZRMpTuf5R7mLA1n2yUaAQocxTaex8bXbdMwTUjPwq6abnzMs2 CtHw== 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=enW5V6g2WX8qHIsfLn2eVhcqKoAKV5YXSn+3ybsOepY=; b=c/p2yOBvVp/H8BxRHQ9rCDe4KvvJxbacduQZy11Tlpf+Rne3TOm9R+pF3TMPei+doT n/zqYD82SafRDYLgur1etrzaALYG9Ot5Kr+JyPcu3C2CyKv03HoaiHSjcpOY2hqth+Nk H3pK92X9tVQylFa9Um857aHLmwFkFgaE4JhJiJvH7pU+J4LmU3su0wuY0DNIjbaxZUku e6rLslFmc5bqNzXAids+bzYPqRFwrlqPj9YFDItBMuc+ps2fjI/SVmGENGXyXJkMV5zs mB5yL8HS91Ss6sWMXLtcjmJgB08TotLnUJkGfCnWb+Cr0t6zje78++a/myC5L5HoJUH2 8W3w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=VnpBQLFt; 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 x186-20020a6386c3000000b0042a46114c85si3164219pgd.514.2022.08.29.01.59.09; Mon, 29 Aug 2022 01:59:19 -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=VnpBQLFt; 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 S230057AbiH2IjH (ORCPT + 99 others); Mon, 29 Aug 2022 04:39:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230038AbiH2IjE (ORCPT ); Mon, 29 Aug 2022 04:39:04 -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 23C9D58536; Mon, 29 Aug 2022 01:39:02 -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=enW5V6g2WX8qHIsfLn2eVhcqKoAKV5YXSn+3ybsOepY=; b=VnpBQLFtOs+d1Mk1xzNicv6GHH 1XXYkxcTGTMvu4i/PhfHDfa4gYaMWhytusRDeWmzGqwH510EOxaBr9SH448WYvQeRHaFYUSKtNJjy k82tW1bgPcjCvPNQhrVMwsm6qzYkRJnJuuZ7JgFtkrrZbLzIcC0WC9okARak/SdAL6EBp0JxqWdZd FyaEeAUG5zUTjLP1/+OrqfBF3TYy1hI109Xw3Fs0y6tFejWbLo/tSBVPLyS+9Okz/sMFHDJlEas3g XjEhoohLZjsY0lWJnze9mBVJ3ZVpoBzdY8gz45bY79ukjf/c9sT17BGlINSzwu8OOt6c+7aSYeKFv bc3iYkKw==; 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 1oSaI2-007RqX-4b; Mon, 29 Aug 2022 08:38:38 +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)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 529D3300137; Mon, 29 Aug 2022 10:38:35 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 0F059202547D2; Mon, 29 Aug 2022 10:38:35 +0200 (CEST) Date: Mon, 29 Aug 2022 10:38:34 +0200 From: Peter Zijlstra To: Marco Elver Cc: Frederic Weisbecker , Ingo Molnar , Thomas Gleixner , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Dmitry Vyukov , Michael Ellerman , linuxppc-dev@lists.ozlabs.org, linux-perf-users@vger.kernel.org, x86@kernel.org, linux-sh@vger.kernel.org, kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 11/14] perf/hw_breakpoint: Reduce contention with large number of tasks Message-ID: References: <20220704150514.48816-1-elver@google.com> <20220704150514.48816-12-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,T_SCC_BODY_TEXT_LINE 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 Wed, Aug 17, 2022 at 03:14:54PM +0200, Marco Elver wrote: > On Wed, 17 Aug 2022 at 15:03, Peter Zijlstra wrote: > > > > On Mon, Jul 04, 2022 at 05:05:11PM +0200, Marco Elver wrote: > > > +static bool bp_constraints_is_locked(struct perf_event *bp) > > > +{ > > > + struct mutex *tsk_mtx = get_task_bps_mutex(bp); > > > + > > > + return percpu_is_write_locked(&bp_cpuinfo_sem) || > > > + (tsk_mtx ? mutex_is_locked(tsk_mtx) : > > > + percpu_is_read_locked(&bp_cpuinfo_sem)); > > > +} > > > > > @@ -426,18 +521,28 @@ static int modify_bp_slot(struct perf_event *bp, u64 old_type, u64 new_type) > > > */ > > > int dbg_reserve_bp_slot(struct perf_event *bp) > > > { > > > - if (mutex_is_locked(&nr_bp_mutex)) > > > + int ret; > > > + > > > + if (bp_constraints_is_locked(bp)) > > > return -1; > > > > > > - return __reserve_bp_slot(bp, bp->attr.bp_type); > > > + /* Locks aren't held; disable lockdep assert checking. */ > > > + lockdep_off(); > > > + ret = __reserve_bp_slot(bp, bp->attr.bp_type); > > > + lockdep_on(); > > > + > > > + return ret; > > > } > > > > > > int dbg_release_bp_slot(struct perf_event *bp) > > > { > > > - if (mutex_is_locked(&nr_bp_mutex)) > > > + if (bp_constraints_is_locked(bp)) > > > return -1; > > > > > > + /* Locks aren't held; disable lockdep assert checking. */ > > > + lockdep_off(); > > > __release_bp_slot(bp, bp->attr.bp_type); > > > + lockdep_on(); > > > > > > return 0; > > > } > > > > Urggghhhh... this is horrible crap. That is, the current code is that > > and this makes it worse :/ > > Heh, yes and when I looked at it I really wanted to see if it can > change. But from what I can tell, when the kernel debugger is being > attached, the kernel does stop everything it does and we need the > horrible thing above to not deadlock. And these dbg_ functions are not > normally used, so I decided to leave it as-is. Suggestions? What context is this ran in? NMI should already have lockdep disabled.