Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp2473806rdb; Wed, 15 Nov 2023 01:31:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IEUoaMwSBuJUpYOHrPsrREo4ChExIaRtTSHioXKx9HQqN1p3S2PNTyzvUHlEL357PEGdgMq X-Received: by 2002:a17:902:bf02:b0:1cc:29ef:df81 with SMTP id bi2-20020a170902bf0200b001cc29efdf81mr4369695plb.41.1700040719132; Wed, 15 Nov 2023 01:31:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700040719; cv=none; d=google.com; s=arc-20160816; b=GWs6JWvfb5hmDy4rG20kMtempr7c9GZBBr80eyxSgTMSMQC6VicKhWO7b9cp8HWxKq kiZgzVVK5DYANbNUh7ddyAoxxLFOAoWgu+kZ27RVkv5VyMrTvJ7YVamVJKpMcdXkKke/ 767UTXgFOOU+usFV55LbzEy25rpI1JNOhope74FvqzS2z5QJkMEFehFK9nlpXmiQUqi3 4IMx4IPyBnR8huUypMEJXz1AxJDu28tqA5X80OiVQqS1w2xxjUtdeNjY5J/4XpT/BUOR imjJZXxpvn3xworBDtOdWCnRuuG7PJOhXwd+GPVY7VjJgiT1E6GxVk5u8JQgWewFetvd Nxeg== 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=sJa3cuAFB3nxTpzcfZbSmQTYSFzKNLTZRZTj6CnRm9M=; fh=8NqlwCxumHDsR1cKRxzg5kD4h6TB4/0AGvZbHI5bWsk=; b=kaX8lIqwZP+HObliML85vi4Thl6b7UdaxG5mTYkwXyM/Q5gRIpSJoCjrrtghYsmz9y HIOMnrSYZmsuNkDYkGmLekzWf8a0MY0zGsEDPFuaVvVCxyKAoDs1Bc8wrKNEiZ6/E0DQ Cr5QA0ZfbY1+/tf9vomqy6bLO4lLCz8C6UwscSjobE6USkOo0pbOLQk509RColGFXRlQ tFbO5As8MfL40Kb3yoU3429WsHVy8JmQqQ6Y99SGnfHDitynWpwPuMqi6yAc/gTxomJP zRiLrmH4HRwtci0XHVP6OrCFguFPgM3BGy/PLvYrcz4gvkrNHcKlmczwXUscOdbjsvbI SoKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=BtktUW4L; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id bb4-20020a170902bc8400b001c9c83947d1si9364802plb.645.2023.11.15.01.31.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 01:31:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=desiato.20200630 header.b=BtktUW4L; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 74099807E837; Wed, 15 Nov 2023 01:31:56 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234737AbjKOJbs (ORCPT + 99 others); Wed, 15 Nov 2023 04:31:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234680AbjKOJbr (ORCPT ); Wed, 15 Nov 2023 04:31:47 -0500 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 7801D9F for ; Wed, 15 Nov 2023 01:31:44 -0800 (PST) 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=sJa3cuAFB3nxTpzcfZbSmQTYSFzKNLTZRZTj6CnRm9M=; b=BtktUW4LeB6M46Kf3juW4vIyzy BQficf+JvtQu8LnIN6VhhAs2aeVaZyZZmAcR5BQdpk5JRzfLM6Cu4nXzTuL88/YAcNSYALtxazSNs aDO2h38EzBkqdtB0iAnfPZ/DwXlMBtEJIQzDo/FDbyqzG8t3gQswDvdEF7+HuppPDWZwt8HRTHIZZ 1/GOibtLiui7ZqE7uElbLM9M9uwJKlthmkQIrdy8PcU884M/BZ60aNuhmMumbuLpvEC7Wu2zcBzLW nmsXuU+ZHYNSZJm4tSqZ2MaeEytQTVBydMde8h5nRw5fU4g+VaFpuPJmfTSCrIllMvEIhW8PyMzKK JBSHTaEQ==; 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.96 #2 (Red Hat Linux)) id 1r3CEn-003tNL-07; Wed, 15 Nov 2023 09:31:34 +0000 Received: by noisy.programming.kicks-ass.net (Postfix, from userid 1000) id B18453002BE; Wed, 15 Nov 2023 10:31:08 +0100 (CET) Date: Wed, 15 Nov 2023 10:31:08 +0100 From: Peter Zijlstra To: Jiri Olsa Cc: mingo@kernel.org, linux-kernel@vger.kernel.org, acme@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, namhyung@kernel.org, irogers@google.com, adrian.hunter@intel.com Subject: Re: [PATCH 01/13] perf: Simplify perf_event_alloc() error path Message-ID: <20231115093108.GA3818@noisy.programming.kicks-ass.net> References: <20231102150919.719936610@infradead.org> <20231102152017.847792675@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 15 Nov 2023 01:31:56 -0800 (PST) On Fri, Nov 03, 2023 at 01:38:05PM +0100, Jiri Olsa wrote: > > -err_callchain_buffer: > > - if (!event->parent) { > > - if (event->attr.sample_type & PERF_SAMPLE_CALLCHAIN) > > - put_callchain_buffers(); > > - } > > hum, so this is now called all the time via __free_event, but it should > be called only if we passed get_callchain_buffers call.. this could screw > up nr_callchain_events number eventually no? Yes, good catch, thanks! Something like the below should handle that, no? --- --- a/include/linux/perf_event.h +++ b/include/linux/perf_event.h @@ -628,14 +628,15 @@ struct swevent_hlist { struct rcu_head rcu_head; }; -#define PERF_ATTACH_CONTEXT 0x01 -#define PERF_ATTACH_GROUP 0x02 -#define PERF_ATTACH_TASK 0x04 -#define PERF_ATTACH_TASK_DATA 0x08 -#define PERF_ATTACH_ITRACE 0x10 -#define PERF_ATTACH_SCHED_CB 0x20 -#define PERF_ATTACH_CHILD 0x40 -#define PERF_ATTACH_EXCLUSIVE 0x80 +#define PERF_ATTACH_CONTEXT 0x0001 +#define PERF_ATTACH_GROUP 0x0002 +#define PERF_ATTACH_TASK 0x0004 +#define PERF_ATTACH_TASK_DATA 0x0008 +#define PERF_ATTACH_ITRACE 0x0010 +#define PERF_ATTACH_SCHED_CB 0x0020 +#define PERF_ATTACH_CHILD 0x0040 +#define PERF_ATTACH_EXCLUSIVE 0x0080 +#define PERF_ATTACH_CALLCHAIN 0x0100 struct bpf_prog; struct perf_cgroup; --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -5166,10 +5166,8 @@ static void perf_addr_filters_splice(str /* vs perf_event_alloc() error */ static void __free_event(struct perf_event *event) { - if (!event->parent) { - if (event->attr.sample_type & PERF_SAMPLE_CALLCHAIN) - put_callchain_buffers(); - } + if (event->attach_state & PERF_ATTACH_CALLCHAIN) + put_callchain_buffers(); kfree(event->addr_filter_ranges); @@ -12065,6 +12063,7 @@ perf_event_alloc(struct perf_event_attr err = get_callchain_buffers(attr->sample_max_stack); if (err) goto err; + event->attach_state |= PERF_ATTACH_CALLCHAIN; } }