Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp4020570rwb; Tue, 16 Aug 2022 12:55:14 -0700 (PDT) X-Google-Smtp-Source: AA6agR7C92J16u9QhKYbjeKVq/L4+eBZip2CVeOq69HeIZvHMa418y8doaZiAshM9aTueiafhW/U X-Received: by 2002:a17:902:ea06:b0:16f:1664:dd31 with SMTP id s6-20020a170902ea0600b0016f1664dd31mr23692035plg.65.1660679714486; Tue, 16 Aug 2022 12:55:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660679714; cv=none; d=google.com; s=arc-20160816; b=wyOjnEH5jT0qL3K7+yAUGTDVkd/NeTJ+aHdwirSG1kLrEPTRM6WeX5zr2B9OHXpv4l P4PU1bMDj0XzngDXKYLo+ulXhfyhuf0PlGbnK2SwMyvkqZB2Ahb5cEYRsXoFQLYElBcM 1yJkaJsaNRJrW8/vWKclS2p1GbqSDZXuRDylOSFpKlJK1eMfL57MXLvnS0UJPr7gXotX N7cdDsF+MGgof614OVrHy7OJHdJ/NrieJr5ytw2mLFsns6mgKzkkA+qsoRJXgN1EC9R9 umkw0iiHAV6cuUrsb6w3HSf2e/r21hhxciG/5D7lvJHzsrGTAdXDdMIMs6nFec/fI2S7 6TJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=DB3RDXbiqCDSqVgc9zvrLPNs4owuTwot4lobP9pmHV4=; b=Y/KXWftFC4T+xI9Y3xWuORVm2SYXs0zE2v0+8aTG2Dv8SfWB+X7sgupyn5U817A39W R91LarHbMQM6QfiFmKaRkbD79DY1TXpbbaQ5p8Gj3SpLXyatt/nGmVD9GPxlnbmVlv/n nlE4kh0n820Tmz9sAuu8HB9foS0VVxBoD/7mDS4P6uuqXqAo7PKvpM7qpMfha7MyKcPU eR/B3auDEwvU3g8uoWIi+efLhZ48NTBJZEItFJipi7+0rvOnifdoOdUgK1xYWBCV0JuO qDwFSqgVo7JoJFDWpbEJVvvxQMHz024zV7x4SuhyeRyqtUyBXe17FvFO0GY6X4eCHrLA /VfA== ARC-Authentication-Results: i=1; mx.google.com; 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 a15-20020a170902eccf00b0016d981e3322si14838404plh.370.2022.08.16.12.55.02; Tue, 16 Aug 2022 12:55:14 -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; 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 S237111AbiHPTYN (ORCPT + 99 others); Tue, 16 Aug 2022 15:24:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237109AbiHPTYK (ORCPT ); Tue, 16 Aug 2022 15:24:10 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA7926BCF4 for ; Tue, 16 Aug 2022 12:24:07 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 04C67B816A4 for ; Tue, 16 Aug 2022 19:24:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CEABBC433C1; Tue, 16 Aug 2022 19:24:03 +0000 (UTC) Date: Tue, 16 Aug 2022 15:24:11 -0400 From: Steven Rostedt To: Krister Johansen Cc: Ingo Molnar , Masami Hiramatsu , David Reaver , linux-kernel@vger.kernel.org, Jiri Olsa , Peter Zijlstra , Frederic Weisbecker Subject: Re: [PATCH 1/1] tracing: fix a WARN from trace_event_dyn_put_ref Message-ID: <20220816152411.086ce631@gandalf.local.home> In-Reply-To: <20220816185418.GA2004@templeofstupid.com> References: <4e43a4eece5f382d1636397fb3c0208f2afe81fc.1660347763.git.kjlx@templeofstupid.com> <20220816122559.17869abc@gandalf.local.home> <20220816185418.GA2004@templeofstupid.com> X-Mailer: Claws Mail 3.17.8 (GTK+ 2.24.33; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.7 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_PASS, 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 Tue, 16 Aug 2022 11:54:18 -0700 Krister Johansen wrote: > What do you think, would either of these be a solution that you would > find acceptable? Actually, I think the issue is that the unreg() calls trace_event_put_ref() but the reg() does not do the try_get_ref(), but the perf_trace_init() does. Which is the broken symmetry. I think if we pull out the trace_event_put_ref() from the unreg() function, we fix the bug and also put back the symmetry. Does this patch work? [ Untested, and not even compiled ] -- Steve diff --git a/kernel/trace/trace_event_perf.c b/kernel/trace/trace_event_perf.c index a114549720d6..61e3a2620fa3 100644 --- a/kernel/trace/trace_event_perf.c +++ b/kernel/trace/trace_event_perf.c @@ -157,7 +157,7 @@ static void perf_trace_event_unreg(struct perf_event *p_event) int i; if (--tp_event->perf_refcount > 0) - goto out; + return; tp_event->class->reg(tp_event, TRACE_REG_PERF_UNREGISTER, NULL); @@ -176,8 +176,6 @@ static void perf_trace_event_unreg(struct perf_event *p_event) perf_trace_buf[i] = NULL; } } -out: - trace_event_put_ref(tp_event); } static int perf_trace_event_open(struct perf_event *p_event) @@ -241,6 +239,7 @@ void perf_trace_destroy(struct perf_event *p_event) mutex_lock(&event_mutex); perf_trace_event_close(p_event); perf_trace_event_unreg(p_event); + trace_event_put_ref(p_event->tp_event); mutex_unlock(&event_mutex); } @@ -292,6 +291,7 @@ void perf_kprobe_destroy(struct perf_event *p_event) mutex_lock(&event_mutex); perf_trace_event_close(p_event); perf_trace_event_unreg(p_event); + trace_event_put_ref(p_event->tp_event); mutex_unlock(&event_mutex); destroy_local_trace_kprobe(p_event->tp_event); @@ -347,6 +347,7 @@ void perf_uprobe_destroy(struct perf_event *p_event) mutex_lock(&event_mutex); perf_trace_event_close(p_event); perf_trace_event_unreg(p_event); + trace_event_put_ref(p_event->tp_event); mutex_unlock(&event_mutex); destroy_local_trace_uprobe(p_event->tp_event); }