From patchwork Fri Jul 28 00:12:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13330982 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 4D9DFECA for ; Fri, 28 Jul 2023 00:13:00 +0000 (UTC) Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F293594 for ; Thu, 27 Jul 2023 17:12:56 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-5704995f964so16841847b3.2 for ; Thu, 27 Jul 2023 17:12:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1690503176; x=1691107976; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=o6neUT/Z5ZxqZSvjTzsd3t4vT8zLu+ilqjGFbF/BwHo=; b=p3UY5OrtqjoAHr4YStHKi65rVDwgAEV7PTWNIAzOHMRRHlj/Q7SO5SS/iWoKuNGKNQ q3KH8pM5awvIVnWOT63BFHtZwwa9Eg1ijQC251g+h0PH1+pOncYTEvnlR8HJPVc1e9Zw zy2Bs+axgBATCD+3uHBG/x3UhoysgCIiCEISgdeClzUhp3C4K/PSNQXAIfZ/egs9XtIc LNUaKQbzbgSGfpDnqiWt7O2TA6OSyg3VFwMTP/o3zYgJ1HL654KUYJIiINd3H+rL9i+4 quOk3i/9iHtGRcOE3yKsB9jhMKECdvcp+GKr49ZFChLE+XmKDMnN3oxeiRt5QV5mIeUn dLyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690503176; x=1691107976; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=o6neUT/Z5ZxqZSvjTzsd3t4vT8zLu+ilqjGFbF/BwHo=; b=In/UNQICv53OoZqMOn0CwHslb7gKxCNmX3ADV3JILX8z7qZu3Guiqh6YV4Cy335UBP sjEir3RtW1c23/0b5wnXESZmIicmuzbY1WWhMfOw3gymfxS+nhAwBwh8r0qnqrkWh6zX 4Y5sFMymn6vijJ863kvFWTgxlpv4yAtp8r3UDPaPt+gFnqeSXOHMAzswmvuvOxc+B1Hz cJuOg6v3/FMQ222oS+aGQuK44tkMJGQSRWg3Zr8eutUUASCD+rqZcm5EYShXxHHXUFNO xVs2j2W3DEXXZ5qZPNPrXo6V6Wa2WbuY9FW10i1y+cKKxa7YZpabF6ouIgs1Inq6X9KT 4J1A== X-Gm-Message-State: ABy/qLZuxEfpkuLBSIlo4cG+fllf6Nzn+Sry9u6WdBvMklWlQEBelSBj 15vnvm7ZqjZxd7PUQWFZgGGCocfl+JdR X-Google-Smtp-Source: APBJJlEt4iXxJP8WryqVeJzhMdGPpRqxcb6Ce1vKD99ePr2ibeCxFflRmitKYAp0ZponEC0d5cc+brXqHo0W X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:3d03:ff18:af30:2dad]) (user=irogers job=sendgmr) by 2002:a05:690c:72b:b0:57a:118a:f31 with SMTP id bt11-20020a05690c072b00b0057a118a0f31mr1109ywb.7.1690503176098; Thu, 27 Jul 2023 17:12:56 -0700 (PDT) Date: Thu, 27 Jul 2023 17:12:10 -0700 In-Reply-To: <20230728001212.457900-1-irogers@google.com> Message-Id: <20230728001212.457900-2-irogers@google.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20230728001212.457900-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog Subject: [PATCH v1 1/3] perf parse-event: Avoid BPF test segv From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Eduard Zingerman , Kan Liang , Rob Herring , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Wang Nan , Wang ShaoBo , YueHaibing , He Kuang Cc: Ian Rogers X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net loc is passed as NULL in tools/perf/tests/bpf.c do_test, meaning errors trigger a segv when trying to access. Add the missing NULL check. Signed-off-by: Ian Rogers --- tools/perf/util/parse-events.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 926d3ac97324..02647313c918 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -758,7 +758,7 @@ int parse_events_load_bpf_obj(struct parse_events_state *parse_state, return 0; errout: - parse_events_error__handle(parse_state->error, param.loc->first_column, + parse_events_error__handle(parse_state->error, param.loc ? param.loc->first_column : 0, strdup(errbuf), strdup("(add -v to see detail)")); return err; } From patchwork Fri Jul 28 00:12:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13330983 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 874BB15A7 for ; Fri, 28 Jul 2023 00:13:01 +0000 (UTC) Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22ACE26B8 for ; Thu, 27 Jul 2023 17:12:59 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-d05883d850fso1420971276.3 for ; Thu, 27 Jul 2023 17:12:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1690503178; x=1691107978; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=I2X6P0O3eO5DQvKAy3ylMNjel4qFpAR57C+PYmMuzQU=; b=Y58fZa/86hus7myw8y86G52HiOjYIdlaYA635qPWRhwD2vNtngQenxs9RIRvQMrUgc NRC27Iscw9fdzF7djOURbiRmfnafMR/LbEzenpccF2wZLu9JiYcPLldpTnkQZhgwklMN J9I5bpiMOo08+jJyWmqAfjUtJ802yYQZxtDQNufCu8ph4jbYYkoNVj9sK8hLGoJuKWJ2 Ee/tmyAWBEA9qXiEX9b1SGDZpTFdV4IL65VFg/AHzH96x3hSAtN6eH6D9Cowo2uyE5KS S9VRcVtciLxXshxUVod7FYAGujCcTk99A3IRq37Dy6R0TJTOAHQAeOevmh+oT9LRSFc5 qYpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690503178; x=1691107978; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=I2X6P0O3eO5DQvKAy3ylMNjel4qFpAR57C+PYmMuzQU=; b=HDhGDRqybFvpP65CSZvDW2JrU7IJlhvQAjDI+82wf1pYxFPxOk+HJLYcXMN3PuQXah u55601V96KwueAFifrPmlztyb8FWzTgJeM6NDy5vkSxJaXviRDVJ4gW4PhxSriJZT0Xe l0TgmIlxkjQoK13mDWjqA471HDs0llQ5/7REJQN0ZenuYrFn7+bVUBDZzy+8HQXiSQIo uvuoV63U1J5Jav8jysbTTZhPvFp5UVIU88DLetgv4NdpUrC9mo34ZYPJMnm/5uqhF+PU kNseLTLGQtmldlz361sUsGKQvCL3P7iZxcjJycbXAwtI50+kK12y00fCcUsgx0C1XtPw cc6Q== X-Gm-Message-State: ABy/qLY/pCCUzdOzNz8PN8t/2DORS6leTpuR9XKmeWzbs39ruQIfTxBi ETaDzI5jxRUYUvVKKPpZlO8kLxCk8eUW X-Google-Smtp-Source: APBJJlGSAV/rnlFF9CkbzbttCzE5bHg41Ew3k+XBgmlwzxDfboXGQ6bbIaw0qztWoGPiL3DK8LPTakkE2IqH X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:3d03:ff18:af30:2dad]) (user=irogers job=sendgmr) by 2002:a05:6902:1804:b0:d07:cb52:a3cf with SMTP id cf4-20020a056902180400b00d07cb52a3cfmr917ybb.5.1690503178333; Thu, 27 Jul 2023 17:12:58 -0700 (PDT) Date: Thu, 27 Jul 2023 17:12:11 -0700 In-Reply-To: <20230728001212.457900-1-irogers@google.com> Message-Id: <20230728001212.457900-3-irogers@google.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20230728001212.457900-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog Subject: [PATCH v1 2/3] perf tools: Revert enable indices setting syntax for BPF map From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Eduard Zingerman , Kan Liang , Rob Herring , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Wang Nan , Wang ShaoBo , YueHaibing , He Kuang Cc: Ian Rogers X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net This reverts commit e571e029bdbf ("perf tools: Enable indices setting syntax for BPF map"). The reverted commit added a notion of arrays that could be set as event terms for BPF events. The parsing hasn't worked over multiple Linux releases. Given the broken nature of the parsing it appears the code isn't in use, nor could I find a way for it to be used to add a test. The original commit contains a test in the commit message, however, running it yields: ``` $ perf record -e './test_bpf_map_3.c/map:channel.value[0,1,2,3...5]=101/' usleep 2 event syntax error: '..pf_map_3.c/map:channel.value[0,1,2,3...5]=101/' \___ parser error Run 'perf list' for a list of valid events Usage: perf record [] [] or: perf record [] -- [] -e, --event event selector. use 'perf list' to list available events ``` Given the code can't be used this commit reverts and removes it. Signed-off-by: Ian Rogers --- tools/perf/util/parse-events.c | 8 +-- tools/perf/util/parse-events.l | 11 --- tools/perf/util/parse-events.y | 122 --------------------------------- 3 files changed, 1 insertion(+), 140 deletions(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 02647313c918..0e2004511cf5 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -800,13 +800,7 @@ parse_events_config_bpf(struct parse_events_state *parse_state, parse_events_error__handle(parse_state->error, idx, strdup(errbuf), - strdup( -"Hint:\tValid config terms:\n" -" \tmap:[].value=[value]\n" -" \tmap:[].event=[event]\n" -"\n" -" \twhere is something like [0,3...5] or [all]\n" -" \t(add -v to see detail)")); + NULL); return err; } } diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l index 99335ec586ae..d7d084cc4140 100644 --- a/tools/perf/util/parse-events.l +++ b/tools/perf/util/parse-events.l @@ -175,7 +175,6 @@ do { \ %x mem %s config %x event -%x array group [^,{}/]*[{][^}]*[}][^,{}/]* event_pmu [^,{}/]+[/][^/]*[/][^,{}/]* @@ -251,14 +250,6 @@ non_digit [^0-9] } } -{ -"]" { BEGIN(config); return ']'; } -{num_dec} { return value(yyscanner, 10); } -{num_hex} { return value(yyscanner, 16); } -, { return ','; } -"\.\.\." { return PE_ARRAY_RANGE; } -} - { /* * Please update config_term_names when new static term is added. @@ -302,8 +293,6 @@ r0x{num_raw_hex} { return str(yyscanner, PE_RAW); } {lc_type}-{lc_op_result} { return lc_str(yyscanner, _parse_state); } {lc_type}-{lc_op_result}-{lc_op_result} { return lc_str(yyscanner, _parse_state); } {name_minus} { return str(yyscanner, PE_NAME); } -\[all\] { return PE_ARRAY_ALL; } -"[" { BEGIN(array); return '['; } @{drv_cfg_term} { return drv_str(yyscanner, PE_DRV_CFG_TERM); } } diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y index 454577f7aff6..5a90e7874c59 100644 --- a/tools/perf/util/parse-events.y +++ b/tools/perf/util/parse-events.y @@ -64,7 +64,6 @@ static void free_list_evsel(struct list_head* list_evsel) %token PE_LEGACY_CACHE %token PE_PREFIX_MEM %token PE_ERROR -%token PE_ARRAY_ALL PE_ARRAY_RANGE %token PE_DRV_CFG_TERM %token PE_TERM_HW %type PE_VALUE @@ -108,11 +107,6 @@ static void free_list_evsel(struct list_head* list_evsel) %type groups %destructor { free_list_evsel ($$); } %type tracepoint_name -%destructor { free ($$.sys); free ($$.event); } -%type array -%type array_term -%type array_terms -%destructor { free ($$.ranges); } %type PE_TERM_HW %destructor { free ($$.str); } @@ -127,7 +121,6 @@ static void free_list_evsel(struct list_head* list_evsel) char *sys; char *event; } tracepoint_name; - struct parse_events_array array; struct hardware_term { char *str; u64 num; @@ -878,121 +871,6 @@ PE_TERM $$ = term; } -| -name_or_raw array '=' name_or_legacy -{ - struct parse_events_term *term; - int err = parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER, $1, $4, &@1, &@4); - - if (err) { - free($1); - free($4); - free($2.ranges); - PE_ABORT(err); - } - term->array = $2; - $$ = term; -} -| -name_or_raw array '=' PE_VALUE -{ - struct parse_events_term *term; - int err = parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, $1, $4, false, &@1, &@4); - - if (err) { - free($1); - free($2.ranges); - PE_ABORT(err); - } - term->array = $2; - $$ = term; -} -| -PE_DRV_CFG_TERM -{ - struct parse_events_term *term; - char *config = strdup($1); - int err; - - if (!config) - YYNOMEM; - err = parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_DRV_CFG, config, $1, &@1, NULL); - if (err) { - free($1); - free(config); - PE_ABORT(err); - } - $$ = term; -} - -array: -'[' array_terms ']' -{ - $$ = $2; -} -| -PE_ARRAY_ALL -{ - $$.nr_ranges = 0; - $$.ranges = NULL; -} - -array_terms: -array_terms ',' array_term -{ - struct parse_events_array new_array; - - new_array.nr_ranges = $1.nr_ranges + $3.nr_ranges; - new_array.ranges = realloc($1.ranges, - sizeof(new_array.ranges[0]) * - new_array.nr_ranges); - if (!new_array.ranges) - YYNOMEM; - memcpy(&new_array.ranges[$1.nr_ranges], $3.ranges, - $3.nr_ranges * sizeof(new_array.ranges[0])); - free($3.ranges); - $$ = new_array; -} -| -array_term - -array_term: -PE_VALUE -{ - struct parse_events_array array; - - array.nr_ranges = 1; - array.ranges = malloc(sizeof(array.ranges[0])); - if (!array.ranges) - YYNOMEM; - array.ranges[0].start = $1; - array.ranges[0].length = 1; - $$ = array; -} -| -PE_VALUE PE_ARRAY_RANGE PE_VALUE -{ - struct parse_events_array array; - - if ($3 < $1) { - struct parse_events_state *parse_state = _parse_state; - struct parse_events_error *error = parse_state->error; - char *err_str; - - if (asprintf(&err_str, "Expected '%ld' to be less-than '%ld'", $3, $1) < 0) - err_str = NULL; - - parse_events_error__handle(error, @1.first_column, err_str, NULL); - YYABORT; - } - array.nr_ranges = 1; - array.ranges = malloc(sizeof(array.ranges[0])); - if (!array.ranges) - YYNOMEM; - array.ranges[0].start = $1; - array.ranges[0].length = $3 - $1 + 1; - $$ = array; -} sep_dc: ':' | From patchwork Fri Jul 28 00:12:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Rogers X-Patchwork-Id: 13330984 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 290A3800 for ; Fri, 28 Jul 2023 00:13:04 +0000 (UTC) Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69E4C26A0 for ; Thu, 27 Jul 2023 17:13:01 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-c0f35579901so1394741276.0 for ; Thu, 27 Jul 2023 17:13:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1690503180; x=1691107980; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=TWz7XL7DQKS0EfsO7HA2MTsxrytCVyGHUhFfdbWDZ6s=; b=IuvFR8BF5x1tWF1G6W+CDSQZV/ETHOkjlt5JLQdNIV3O6uadOqnLA7xXftF9bM1JRJ on3qOQgxzN77vfUrqRid2baZtPRCfB9sIRH5BCkItKwFeqszmlmOn5YSBgft7bE7z/6Q optwoMN3KaiZrIGku9DTaf4OIfHXFoNsmZF0uQ3EIckjvyynrnwAtaa58wWI+6s2Ig65 wVEfTqaXWXIyKp8vHk3ROuUMRureFKatzpizPZ6FYru+IrCB8wbfKnL/ZJRjTP7f7J7m PGqB7U2SoXoG1l6H6j360dMT4DCVrFFPBUho6CaHWZEJrgfmiER5JUHJS/YwGAZN4WIF wB3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690503180; x=1691107980; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=TWz7XL7DQKS0EfsO7HA2MTsxrytCVyGHUhFfdbWDZ6s=; b=CY7pKE3V+6oDapfgl//4yaj7BUk1tMjgjYn/HnB3IpOyJ0WkLsOMcIEub7dUYbENw3 zQ//FytLaxJdENg6yEGIidINIFlWNLXYM9sreEf9aIvDceADRw9FmX3EusssHy9EatcM MBZ66heZR3MnnOPVjqSi6q3UJX8SAM363x3q9G9wT8NU8oxpAjDZo19yEOBRCOYTEFA6 7/VQmRSJtb0Z0wVRWJgrC6i5RbBTSuY1Kugaq0XO1eqsAp3NXy41/kWyAbjSexnvqG74 wkEIP697l0u2S365I3Ug/WtitcCXEyGBFJuikQnp1Ea+QdDNo84msgy67YkY+0cnC2e6 Di5w== X-Gm-Message-State: ABy/qLZ1H1E/uXbje3bW9dIu64NSjufHEwIEyATknLY4ZRDu7PQhf0mC nbl/xAzCgujYjPXDsWHW41RUFdaGYLx8 X-Google-Smtp-Source: APBJJlFpuxfDhuyA9wPq1j8ekeU8floVzkUu1hEuEp9+trKyCpF1P2gF/EEdIZPyXLG7MeOx8eR5n175A9UL X-Received: from irogers.svl.corp.google.com ([2620:15c:2a3:200:3d03:ff18:af30:2dad]) (user=irogers job=sendgmr) by 2002:a05:6902:569:b0:d11:3c58:2068 with SMTP id a9-20020a056902056900b00d113c582068mr1077ybt.2.1690503180537; Thu, 27 Jul 2023 17:13:00 -0700 (PDT) Date: Thu, 27 Jul 2023 17:12:12 -0700 In-Reply-To: <20230728001212.457900-1-irogers@google.com> Message-Id: <20230728001212.457900-4-irogers@google.com> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20230728001212.457900-1-irogers@google.com> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog Subject: [PATCH v1 3/3] perf parse-events: Remove array remnants From: Ian Rogers To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Adrian Hunter , Eduard Zingerman , Kan Liang , Rob Herring , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, Wang Nan , Wang ShaoBo , YueHaibing , He Kuang Cc: Ian Rogers X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net parse_events_array was set up by event term parsing, which no longer exists. Remove this struct and references to it. Signed-off-by: Ian Rogers --- tools/perf/util/bpf-loader.c | 101 --------------------------------- tools/perf/util/parse-events.c | 8 --- tools/perf/util/parse-events.h | 10 ---- 3 files changed, 119 deletions(-) diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c index 44cde27d6389..108eca9ddad4 100644 --- a/tools/perf/util/bpf-loader.c +++ b/tools/perf/util/bpf-loader.c @@ -1091,16 +1091,12 @@ enum bpf_map_op_type { enum bpf_map_key_type { BPF_MAP_KEY_ALL, - BPF_MAP_KEY_RANGES, }; struct bpf_map_op { struct list_head list; enum bpf_map_op_type op_type; enum bpf_map_key_type key_type; - union { - struct parse_events_array array; - } k; union { u64 value; struct evsel *evsel; @@ -1116,8 +1112,6 @@ bpf_map_op__delete(struct bpf_map_op *op) { if (!list_empty(&op->list)) list_del_init(&op->list); - if (op->key_type == BPF_MAP_KEY_RANGES) - parse_events__clear_array(&op->k.array); free(op); } @@ -1196,18 +1190,6 @@ bpf_map_op_setkey(struct bpf_map_op *op, struct parse_events_term *term) if (!term) return 0; - if (term->array.nr_ranges) { - size_t memsz = term->array.nr_ranges * - sizeof(op->k.array.ranges[0]); - - op->k.array.ranges = memdup(term->array.ranges, memsz); - if (!op->k.array.ranges) { - pr_debug("Not enough memory to alloc indices for map\n"); - return -ENOMEM; - } - op->key_type = BPF_MAP_KEY_RANGES; - op->k.array.nr_ranges = term->array.nr_ranges; - } return 0; } @@ -1244,18 +1226,6 @@ bpf_map_op__clone(struct bpf_map_op *op) } INIT_LIST_HEAD(&newop->list); - if (op->key_type == BPF_MAP_KEY_RANGES) { - size_t memsz = op->k.array.nr_ranges * - sizeof(op->k.array.ranges[0]); - - newop->k.array.ranges = memdup(op->k.array.ranges, memsz); - if (!newop->k.array.ranges) { - pr_debug("Failed to alloc indices for map\n"); - free(newop); - return NULL; - } - } - return newop; } @@ -1456,40 +1426,6 @@ struct bpf_obj_config__map_func bpf_obj_config__map_funcs[] = { {"event", bpf_map__config_event}, }; -static int -config_map_indices_range_check(struct parse_events_term *term, - struct bpf_map *map, - const char *map_name) -{ - struct parse_events_array *array = &term->array; - unsigned int i; - - if (!array->nr_ranges) - return 0; - if (!array->ranges) { - pr_debug("ERROR: map %s: array->nr_ranges is %d but range array is NULL\n", - map_name, (int)array->nr_ranges); - return -BPF_LOADER_ERRNO__INTERNAL; - } - - if (!map) { - pr_debug("Map '%s' is invalid\n", map_name); - return -BPF_LOADER_ERRNO__INTERNAL; - } - - for (i = 0; i < array->nr_ranges; i++) { - unsigned int start = array->ranges[i].start; - size_t length = array->ranges[i].length; - unsigned int idx = start + length - 1; - - if (idx >= bpf_map__max_entries(map)) { - pr_debug("ERROR: index %d too large\n", idx); - return -BPF_LOADER_ERRNO__OBJCONF_MAP_IDX2BIG; - } - } - return 0; -} - static int bpf__obj_config_map(struct bpf_object *obj, struct parse_events_term *term, @@ -1525,12 +1461,6 @@ bpf__obj_config_map(struct bpf_object *obj, goto out; } - *key_scan_pos += strlen(map_opt); - err = config_map_indices_range_check(term, map, map_name); - if (err) - goto out; - *key_scan_pos -= strlen(map_opt); - for (i = 0; i < ARRAY_SIZE(bpf_obj_config__map_funcs); i++) { struct bpf_obj_config__map_func *func = &bpf_obj_config__map_funcs[i]; @@ -1579,7 +1509,6 @@ typedef int (*map_config_func_t)(const char *name, int map_fd, const struct bpf_map *map, struct bpf_map_op *op, void *pkey, void *arg); - static int foreach_key_array_all(map_config_func_t func, void *arg, const char *name, @@ -1600,32 +1529,6 @@ foreach_key_array_all(map_config_func_t func, return 0; } -static int -foreach_key_array_ranges(map_config_func_t func, void *arg, - const char *name, int map_fd, - const struct bpf_map *map, - struct bpf_map_op *op) -{ - unsigned int i, j; - int err; - - for (i = 0; i < op->k.array.nr_ranges; i++) { - unsigned int start = op->k.array.ranges[i].start; - size_t length = op->k.array.ranges[i].length; - - for (j = 0; j < length; j++) { - unsigned int idx = start + j; - - err = func(name, map_fd, map, op, &idx, arg); - if (err) { - pr_debug("ERROR: failed to insert value to %s[%u]\n", - name, idx); - return err; - } - } - } - return 0; -} static int bpf_map_config_foreach_key(struct bpf_map *map, @@ -1666,10 +1569,6 @@ bpf_map_config_foreach_key(struct bpf_map *map, err = foreach_key_array_all(func, arg, name, map_fd, map, op); break; - case BPF_MAP_KEY_RANGES: - err = foreach_key_array_ranges(func, arg, name, - map_fd, map, op); - break; default: pr_debug("ERROR: keytype for map '%s' invalid\n", name); diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 0e2004511cf5..70841b0febf3 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -2717,9 +2717,6 @@ int parse_events_term__clone(struct parse_events_term **new, void parse_events_term__delete(struct parse_events_term *term) { - if (term->array.nr_ranges) - zfree(&term->array.ranges); - if (term->type_val != PARSE_EVENTS__TERM_TYPE_NUM) zfree(&term->val.str); @@ -2770,11 +2767,6 @@ void parse_events_terms__delete(struct list_head *terms) free(terms); } -void parse_events__clear_array(struct parse_events_array *a) -{ - zfree(&a->ranges); -} - void parse_events_evlist_error(struct parse_events_state *parse_state, int idx, const char *str) { diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index e59b33805886..b77ff619a623 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -81,17 +81,8 @@ enum { __PARSE_EVENTS__TERM_TYPE_NR, }; -struct parse_events_array { - size_t nr_ranges; - struct { - unsigned int start; - size_t length; - } *ranges; -}; - struct parse_events_term { char *config; - struct parse_events_array array; union { char *str; u64 num; @@ -162,7 +153,6 @@ int parse_events_term__clone(struct parse_events_term **new, void parse_events_term__delete(struct parse_events_term *term); void parse_events_terms__delete(struct list_head *terms); void parse_events_terms__purge(struct list_head *terms); -void parse_events__clear_array(struct parse_events_array *a); int parse_events__modifier_event(struct list_head *list, char *str, bool add); int parse_events__modifier_group(struct list_head *list, char *event_mod); int parse_events_name(struct list_head *list, const char *name);