Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp823289rwb; Mon, 26 Sep 2022 06:22:02 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4BRDDlfCyqnH0h31AmOPwdpeuMj2z9oLR0F85ArnIZ8BTVVxkA25228dRpHByj2j/g4slw X-Received: by 2002:a17:902:d58f:b0:179:b756:6f5e with SMTP id k15-20020a170902d58f00b00179b7566f5emr10689347plh.1.1664198522158; Mon, 26 Sep 2022 06:22:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664198522; cv=none; d=google.com; s=arc-20160816; b=k3jlxEAi/XVp5SSKnjKmkGt1nQMHHp3TbjPtlJf3ByPTZRyFwl9b2EWqPEYTH0HfSK EeltdWicBJzeGA13J4aIHlD36IJngDKFiD/HX3rV8rmrMzJJv9mPIsz/yb7V6SBa8XvK 9GWyw1JDzr9f3mwC1VXdBk4WEIqmxxVr0Cto0W0VATNpEysHNubQkbadZqdPcUcI5NK+ GuN0lu1fwbrhUZh4NASRuhtwb1vpPaQg6pOCTSa4PpTfJ4uPF3LWBRyGZ9XeQxLlRxjW QD0XSzDUfH3IpVHN3Tqp0uT6O70GCyniltZNELIotsSLu/260nKb7QMNEbtEMa/IJlc5 OH1Q== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=vbbycE0n87Q1gsHYO81On46vWcrcmzoqU4mcAE7svhw=; b=Mex8bDyw4Zed2Ay0B4oi5crfhBSnBiVLmk9qpBlUF8bhauJmUS/+5aobA/tpC/GlBC ebI0y9b1zKJvlAtOyoOO/GrnD6401YIW7Km+y3Ic825byyux/qsBald8KojBnLuS4ShB 6B5jPvLFO4dDgvA+Kznd/G8f17Q1Ab0rIws/PXDhn4e6p4Yrc1Klt+h10uDEZh30xvDA t8rW2YVTHa1m5mNEmddwAZvK8otIcLaT7DSU83YvOspNSRmiIjXJuVonvMsoWKsvyOFO 4+4N3hdJiAmhlKmkAh61jlSoHoK1bOgn59LVzumLZ/BpMKr1kmeJqh7lMUg3nvMizPq9 TeuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="j/aKFhIu"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h71-20020a63834a000000b0043c87ece306si1361493pge.534.2022.09.26.06.21.50; Mon, 26 Sep 2022 06:22:02 -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=@linuxfoundation.org header.s=korg header.b="j/aKFhIu"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238987AbiIZL5L (ORCPT + 99 others); Mon, 26 Sep 2022 07:57:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239129AbiIZLyj (ORCPT ); Mon, 26 Sep 2022 07:54:39 -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 4B5CD4D835; Mon, 26 Sep 2022 03:50:16 -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 451D9B802C7; Mon, 26 Sep 2022 10:48:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 77956C433D6; Mon, 26 Sep 2022 10:48:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1664189315; bh=iaB1KodNW2681CtVUDHZXZv/QS5f3KAqBTUzxLWxXwM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=j/aKFhIurr/fX+Wx7+hNjUI9E/YHDx9qyCXkO2KdSdVYJgCQrrybWkOidPNZzZpbU eiwuHYgJTnsSp4xgQXmcxNLVNBik+mk6/2xudsV+oe9YOqE5AJKCxOqECuki7aHovl cAqqhOmhLJ+5aUbjD+n88NxiX7f+GTzI6UdD9UHA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Namhyung Kim , Adrian Hunter , bpf@vger.kernel.org, Ian Rogers , Ingo Molnar , Jiri Olsa , Peter Zijlstra , Song Liu , Arnaldo Carvalho de Melo , Sasha Levin Subject: [PATCH 5.19 146/207] perf stat: Fix cpu map index in bperf cgroup code Date: Mon, 26 Sep 2022 12:12:15 +0200 Message-Id: <20220926100813.049490680@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220926100806.522017616@linuxfoundation.org> References: <20220926100806.522017616@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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 From: Namhyung Kim [ Upstream commit 3da35231d9e4949c4ae40e3ce653e7c468455d55 ] The previous cpu map introduced a bug in the bperf cgroup counter. This results in a failure when user gives a partial cpu map starting from non-zero. $ sudo ./perf stat -C 1-2 --bpf-counters --for-each-cgroup ^. sleep 1 libbpf: prog 'on_cgrp_switch': failed to create BPF link for perf_event FD 0: -9 (Bad file descriptor) Failed to attach cgroup program To get the FD of an evsel, it should use a map index not the CPU number. Fixes: 0255571a16059c8e ("perf cpumap: Switch to using perf_cpu_map API") Signed-off-by: Namhyung Kim Cc: Adrian Hunter Cc: bpf@vger.kernel.org Cc: Ian Rogers Cc: Ingo Molnar Cc: Jiri Olsa Cc: Peter Zijlstra Cc: Song Liu Link: https://lore.kernel.org/r/20220916184132.1161506-3-namhyung@kernel.org Signed-off-by: Arnaldo Carvalho de Melo Signed-off-by: Sasha Levin --- tools/perf/util/bpf_counter_cgroup.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/bpf_counter_cgroup.c b/tools/perf/util/bpf_counter_cgroup.c index 63b9db657442..97c69a249c6e 100644 --- a/tools/perf/util/bpf_counter_cgroup.c +++ b/tools/perf/util/bpf_counter_cgroup.c @@ -95,7 +95,7 @@ static int bperf_load_program(struct evlist *evlist) perf_cpu_map__for_each_cpu(cpu, i, evlist->core.all_cpus) { link = bpf_program__attach_perf_event(skel->progs.on_cgrp_switch, - FD(cgrp_switch, cpu.cpu)); + FD(cgrp_switch, i)); if (IS_ERR(link)) { pr_err("Failed to attach cgroup program\n"); err = PTR_ERR(link); @@ -123,7 +123,7 @@ static int bperf_load_program(struct evlist *evlist) map_fd = bpf_map__fd(skel->maps.events); perf_cpu_map__for_each_cpu(cpu, j, evlist->core.all_cpus) { - int fd = FD(evsel, cpu.cpu); + int fd = FD(evsel, j); __u32 idx = evsel->core.idx * total_cpus + cpu.cpu; err = bpf_map_update_elem(map_fd, &idx, &fd, -- 2.35.1