Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp716629rdf; Fri, 3 Nov 2023 12:50:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHgwEogNLH7huW3nvD3UGCFp0T4+O868W460dciwMk7aoeOfCR9S/+G979uLNBdcHsR97U1 X-Received: by 2002:a17:902:8695:b0:1ca:7a4c:834e with SMTP id g21-20020a170902869500b001ca7a4c834emr15614617plo.69.1699041047044; Fri, 03 Nov 2023 12:50:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699041047; cv=none; d=google.com; s=arc-20160816; b=jwpeG6wHX6TXmF8fxm3sM8JFn2lRhkN5c9xG/CXAe8ynGGxpZj+acrerIQbV2T5r6j P0O1iK/W7zWOknaBmF5eS2iXsS6Zr3Ynd/sxQrjQQbL+frd5KhHDdxaivMaXYouH5Sz/ Nuyfk8bPxpvCbSx/MZTQ5gcOG/HwA3TcKOcHc7sjBIW50/5orVR/RwJrtP6Ccs5ENqmm hO0EJY1bJFZD8o1rshySiOZ8hzM6Wi53aHrcRDiicCuQ2JvePTbvr5ivjErFQItmOmv4 mRNE6TuLgfufiCJY/mxXlCucssOM7pnSSCUGTXBGa8PytBdwvaWDw1raPhtx/jd6yhvj SSnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=dzXhD8uxVq10bQRgZDavXZdLnY3vcRwwr8/7FjPNZt8=; fh=XoC8oz2D9a1yAqNmW4y8zzLM2EknEzjFC5zR+OKOay8=; b=ziYLkn9YXgE5M+BQ0hAlF+lunmqqnQBoAxHfhSjcN8T3Ap54sRDKc1CGJjrzBG4Zgv /kbs9Yn7RMtlFxUrT83zu31LBPgrIbfVKzhEHmPOsq1sXIWML6Z/3+yJUvKvW8jhpZqs WoHahYC+ZwnwKl8e58QPYjEgTPWGvaC2GXagE+uIP8SWLI+EHoBvPjv+REmWtU0Zgl56 qPXDUgYJ37qV+cVM/Xj7QMzjBqQOHF9PcCJLUIOzGXx6gNO1lcSNDipj2E/I7p/GQuP7 MHr5QyhVCufTXQGa6nbehLAZiJdWAYHbK+Yf7RVLzTOvSI8oU+8LfP878YdDgyyQx00L nhaQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id h10-20020a170902f54a00b001ca1bd1e09bsi2189240plf.376.2023.11.03.12.50.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 12:50:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id CEDB48313359; Fri, 3 Nov 2023 12:50:44 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377621AbjKCTue convert rfc822-to-8bit (ORCPT + 99 others); Fri, 3 Nov 2023 15:50:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229689AbjKCTud (ORCPT ); Fri, 3 Nov 2023 15:50:33 -0400 Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31A66D4E for ; Fri, 3 Nov 2023 12:50:31 -0700 (PDT) Received: by mail-pj1-f50.google.com with SMTP id 98e67ed59e1d1-28023eadc70so2417197a91.2 for ; Fri, 03 Nov 2023 12:50:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699041030; x=1699645830; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8+9uIel5PccOA8PHoSqpnvZ3HoedGl5aV/O8FGCyQEc=; b=CaVK3fkTfezTltzrlQmVvjxhH+ikXRpPnjMaxn0bbA5+8Z2kVxA1CUZ0rNl85mJfEQ 44MOfb1I50tt0AIUtqPhNROPq9MmxCqHDM7FZWFkuyjPwO9c/HIAMKyT9F2GIZ2CXR8o 1CHxsOpC+ZZnw/UOHmYw+E4C1D8bgQrQ/aivA5y0bzQlBwLUY0tZK5V11M+OKEKLLQLx HEufwecgbVBXqKczjBfMMmOsn65Z1MPgN6YCjVInPUlR2UW+9Dz6AAuHDFflyGYY4x/x DXJ5Z8l+hVTtUDSz5Qxov3VxSsfcxurPZBcQ86YAf4UGewEonmOgP1a7PxwkTos45h/8 k+nw== X-Gm-Message-State: AOJu0YwlbRbN5yfUu5ApoLdTdTRX8DhjjvGoN92m6lg1ntSX7I6/ywl3 Bj4Hk0hGnR9AOSpDtpSgggP+SR0mvbin5tDYNrk= X-Received: by 2002:a17:90a:49ca:b0:27c:f1f8:261f with SMTP id l10-20020a17090a49ca00b0027cf1f8261fmr18389928pjm.20.1699041030547; Fri, 03 Nov 2023 12:50:30 -0700 (PDT) MIME-Version: 1.0 References: <20231102150919.719936610@infradead.org> <20231102152017.847792675@infradead.org> In-Reply-To: From: Namhyung Kim Date: Fri, 3 Nov 2023 12:50:19 -0700 Message-ID: Subject: Re: [PATCH 01/13] perf: Simplify perf_event_alloc() error path To: Jiri Olsa Cc: Peter Zijlstra , mingo@kernel.org, linux-kernel@vger.kernel.org, acme@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, irogers@google.com, adrian.hunter@intel.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 03 Nov 2023 12:50:44 -0700 (PDT) Hi Jiri and Peter, On Fri, Nov 3, 2023 at 5:38 AM Jiri Olsa wrote: > > On Thu, Nov 02, 2023 at 04:09:20PM +0100, Peter Zijlstra wrote: > > SNIP > > > @@ -11936,24 +11957,24 @@ perf_event_alloc(struct perf_event_attr > > */ > > if (pmu->task_ctx_nr == perf_invalid_context && (task || cgroup_fd != -1)) { > > err = -EINVAL; > > - goto err_pmu; > > + goto err; > > } > > > > if (event->attr.aux_output && > > !(pmu->capabilities & PERF_PMU_CAP_AUX_OUTPUT)) { > > err = -EOPNOTSUPP; > > - goto err_pmu; > > + goto err; > > } > > > > if (cgroup_fd != -1) { > > err = perf_cgroup_connect(cgroup_fd, event, attr, group_leader); > > if (err) > > - goto err_pmu; > > + goto err; > > } > > > > err = exclusive_event_init(event); > > if (err) > > - goto err_pmu; > > + goto err; > > > > if (has_addr_filter(event)) { > > event->addr_filter_ranges = kcalloc(pmu->nr_addr_filters, > > @@ -11961,7 +11982,7 @@ perf_event_alloc(struct perf_event_attr > > GFP_KERNEL); > > if (!event->addr_filter_ranges) { > > err = -ENOMEM; > > - goto err_per_task; > > + goto err; > > } > > > > /* > > @@ -11986,41 +12007,21 @@ perf_event_alloc(struct perf_event_attr > > if (event->attr.sample_type & PERF_SAMPLE_CALLCHAIN) { > > err = get_callchain_buffers(attr->sample_max_stack); > > if (err) > > - goto err_addr_filters; > > + goto err; > > } > > } > > > > err = security_perf_event_alloc(event); > > if (err) > > - goto err_callchain_buffer; > > + goto err; > > > > /* symmetric to unaccount_event() in _free_event() */ > > account_event(event); > > > > return event; > > > > -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? Looks like so. > > jirka > > > -err_addr_filters: > > - kfree(event->addr_filter_ranges); > > - > > -err_per_task: > > - exclusive_event_destroy(event); > > - > > -err_pmu: > > - if (is_cgroup_event(event)) > > - perf_detach_cgroup(event); > > - if (event->destroy) > > - event->destroy(event); > > - module_put(pmu->module); I'm afraid of this part. If it failed at perf_init_event(), it might call event->destroy() already. I saw you cleared event->pmu in the failure path. Maybe we need the same thing for the event->destroy. Thanks, Namhyung > > -err_ns: > > - if (event->hw.target) > > - put_task_struct(event->hw.target); > > - call_rcu(&event->rcu_head, free_event_rcu); > > - > > +err: > > + __free_event(event); > > return ERR_PTR(err); > > } > > > > > >