From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BDB78C001DF for ; Mon, 7 Aug 2023 21:19:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229559AbjHGVTg (ORCPT ); Mon, 7 Aug 2023 17:19:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230271AbjHGVTf (ORCPT ); Mon, 7 Aug 2023 17:19:35 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92FFFE7F for ; Mon, 7 Aug 2023 14:19:34 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 25D8662252 for ; Mon, 7 Aug 2023 21:19:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5A316C433C9; Mon, 7 Aug 2023 21:19:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691443173; bh=xZZy1LMAyCIz0vNMcgNk01VXZ57vkAT/9FTncjwi7jM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=TUHCOgov6scJzivL96MPzt+BMxji2V8FgxHkCMbl3GH6K2s1VtvhqXDmKy4/vSibT OWyNV6gOSAYv/MQcaFA+jjVRCx+qpkmm56K2mU/T0846pH6+hIsSTFc4gtd2iwDFWm HH21uzK1qQ5PQEQd2FQyiVFZ7aQ4sMxnKgBKWhIG6s5QPKlR5bdEmPZCPrfiGck5QQ 0kybmRi6Zxt+AHCg8NTFbGGi8754Bd44z3UeyUhysTzgB8nLm/n+6U1QzFlv5uG3/M Q1ohXxRNye7z9KuyF6lzTrcaY1PRth32Ne0sEF3r4ozKzKypRHE21XA9NLPPFH11R2 5LyqLJwL61npw== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id CCE38404DF; Mon, 7 Aug 2023 18:19:30 -0300 (-03) Date: Mon, 7 Aug 2023 18:19:30 -0300 From: Arnaldo Carvalho de Melo To: Disha Goel Cc: Athira Rajeev , jolsa@kernel.org, irogers@google.com, namhyung@kernel.org, linux-perf-users@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, maddy@linux.ibm.com, kjain@linux.ibm.com, disgoel@linux.vnet.ibm.com Subject: Re: [PATCH V2 2/2] tools/perf/tests: perf all metricgroups test fails when perf_event access is restricted Message-ID: References: <20230804050047.94240-1-atrajeev@linux.vnet.ibm.com> <20230804050047.94240-2-atrajeev@linux.vnet.ibm.com> <3c0eb25b-a51b-edba-82ea-22e6d2b07978@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3c0eb25b-a51b-edba-82ea-22e6d2b07978@linux.ibm.com> X-Url: http://acmel.wordpress.com Precedence: bulk List-ID: X-Mailing-List: linux-perf-users@vger.kernel.org Em Mon, Aug 07, 2023 at 08:14:39PM +0530, Disha Goel escreveu: > On 04/08/23 10:30 am, Athira Rajeev wrote: > > Perf all metricgroups test fails as below when perf_event access > > is restricted. > > > > ./perf test -v "perf all metricgroups test" > > Testing Memory_BW > > Error: > > Access to performance monitoring and observability operations is limited. > > Enforced MAC policy settings (SELinux) can limit access to performance > > access to performance monitoring and observability operations for processes > > without CAP_PERFMON, CAP_SYS_PTRACE or CAP_SYS_ADMIN Linux capability. > > > > test child finished with -1 > > ---- end ---- > > perf all metricgroups test: FAILED! > > > > Fix the testcase to skip those metric events which needs perf_event access > > explicitly. The exit code of the testcase is based on return code of > > the perf stat command ( enabled by set -e option ). Hence save the > > exit status in a variable and use that to decide success or fail for the > > testcase. I wonder if we shouldn't somehow check if the credentials needed to performing a test shouldn't be checked before trying it. This way we would check if the check that the tool or the kernel is doing is the appropriate one. I.e. the kernel refusal for doing something may be an error. - Arnaldo > > Signed-off-by: Athira Rajeev > > With this patch applied(on power) perf metricgroups test works correctly when perf_event access is restricted. > > # ./perf test "perf all metricgroups test" > 96: perf all metricgroups test : Ok > > Tested-by: Disha Goel > > > --- > > Changelog: > > v1 -> v2: > > Changed the condition to use "echo" and "grep" so it works on > > Posix shell as well. > > > > tools/perf/tests/shell/stat_all_metricgroups.sh | 14 +++++++++++--- > > 1 file changed, 11 insertions(+), 3 deletions(-) > > > > diff --git a/tools/perf/tests/shell/stat_all_metricgroups.sh b/tools/perf/tests/shell/stat_all_metricgroups.sh > > index cb35e488809a..eaa5e1172294 100755 > > --- a/tools/perf/tests/shell/stat_all_metricgroups.sh > > +++ b/tools/perf/tests/shell/stat_all_metricgroups.sh > > @@ -2,11 +2,19 @@ > > # perf all metricgroups test > > # SPDX-License-Identifier: GPL-2.0 > > > > -set -e > > - > > for m in $(perf list --raw-dump metricgroups); do > > echo "Testing $m" > > - perf stat -M "$m" -a true > > + result=$(perf stat -M "$m" -a true 2>&1) > > + rc=$? > > + # Skip if there is no access to perf_events monitoring > > + # Otherwise exit based on the return code of perf comamnd. > > + if echo "$result" | grep -q "Access to performance monitoring and observability operations is limited"; > > + then > > + continue > > + else > > + [ $rc -ne 0 ] && exit $rc > > + fi > > + > > done > > > > exit 0 -- - Arnaldo From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6B4A6C001B0 for ; Mon, 7 Aug 2023 21:22:27 +0000 (UTC) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=TUHCOgov; dkim-atps=neutral Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4RKTmd4yCPz2ywt for ; Tue, 8 Aug 2023 07:22:25 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=TUHCOgov; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=kernel.org (client-ip=139.178.84.217; helo=dfw.source.kernel.org; envelope-from=acme@kernel.org; receiver=lists.ozlabs.org) Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4RKTjN3YsNz2yVv for ; Tue, 8 Aug 2023 07:19:36 +1000 (AEST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2246C6224B; Mon, 7 Aug 2023 21:19:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5A316C433C9; Mon, 7 Aug 2023 21:19:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691443173; bh=xZZy1LMAyCIz0vNMcgNk01VXZ57vkAT/9FTncjwi7jM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=TUHCOgov6scJzivL96MPzt+BMxji2V8FgxHkCMbl3GH6K2s1VtvhqXDmKy4/vSibT OWyNV6gOSAYv/MQcaFA+jjVRCx+qpkmm56K2mU/T0846pH6+hIsSTFc4gtd2iwDFWm HH21uzK1qQ5PQEQd2FQyiVFZ7aQ4sMxnKgBKWhIG6s5QPKlR5bdEmPZCPrfiGck5QQ 0kybmRi6Zxt+AHCg8NTFbGGi8754Bd44z3UeyUhysTzgB8nLm/n+6U1QzFlv5uG3/M Q1ohXxRNye7z9KuyF6lzTrcaY1PRth32Ne0sEF3r4ozKzKypRHE21XA9NLPPFH11R2 5LyqLJwL61npw== Received: by quaco.ghostprotocols.net (Postfix, from userid 1000) id CCE38404DF; Mon, 7 Aug 2023 18:19:30 -0300 (-03) Date: Mon, 7 Aug 2023 18:19:30 -0300 From: Arnaldo Carvalho de Melo To: Disha Goel Subject: Re: [PATCH V2 2/2] tools/perf/tests: perf all metricgroups test fails when perf_event access is restricted Message-ID: References: <20230804050047.94240-1-atrajeev@linux.vnet.ibm.com> <20230804050047.94240-2-atrajeev@linux.vnet.ibm.com> <3c0eb25b-a51b-edba-82ea-22e6d2b07978@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3c0eb25b-a51b-edba-82ea-22e6d2b07978@linux.ibm.com> X-Url: http://acmel.wordpress.com X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: irogers@google.com, Athira Rajeev , kjain@linux.ibm.com, linux-perf-users@vger.kernel.org, maddy@linux.ibm.com, jolsa@kernel.org, namhyung@kernel.org, disgoel@linux.vnet.ibm.com, linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" Em Mon, Aug 07, 2023 at 08:14:39PM +0530, Disha Goel escreveu: > On 04/08/23 10:30 am, Athira Rajeev wrote: > > Perf all metricgroups test fails as below when perf_event access > > is restricted. > > > > ./perf test -v "perf all metricgroups test" > > Testing Memory_BW > > Error: > > Access to performance monitoring and observability operations is limited. > > Enforced MAC policy settings (SELinux) can limit access to performance > > access to performance monitoring and observability operations for processes > > without CAP_PERFMON, CAP_SYS_PTRACE or CAP_SYS_ADMIN Linux capability. > > > > test child finished with -1 > > ---- end ---- > > perf all metricgroups test: FAILED! > > > > Fix the testcase to skip those metric events which needs perf_event access > > explicitly. The exit code of the testcase is based on return code of > > the perf stat command ( enabled by set -e option ). Hence save the > > exit status in a variable and use that to decide success or fail for the > > testcase. I wonder if we shouldn't somehow check if the credentials needed to performing a test shouldn't be checked before trying it. This way we would check if the check that the tool or the kernel is doing is the appropriate one. I.e. the kernel refusal for doing something may be an error. - Arnaldo > > Signed-off-by: Athira Rajeev > > With this patch applied(on power) perf metricgroups test works correctly when perf_event access is restricted. > > # ./perf test "perf all metricgroups test" > 96: perf all metricgroups test : Ok > > Tested-by: Disha Goel > > > --- > > Changelog: > > v1 -> v2: > > Changed the condition to use "echo" and "grep" so it works on > > Posix shell as well. > > > > tools/perf/tests/shell/stat_all_metricgroups.sh | 14 +++++++++++--- > > 1 file changed, 11 insertions(+), 3 deletions(-) > > > > diff --git a/tools/perf/tests/shell/stat_all_metricgroups.sh b/tools/perf/tests/shell/stat_all_metricgroups.sh > > index cb35e488809a..eaa5e1172294 100755 > > --- a/tools/perf/tests/shell/stat_all_metricgroups.sh > > +++ b/tools/perf/tests/shell/stat_all_metricgroups.sh > > @@ -2,11 +2,19 @@ > > # perf all metricgroups test > > # SPDX-License-Identifier: GPL-2.0 > > > > -set -e > > - > > for m in $(perf list --raw-dump metricgroups); do > > echo "Testing $m" > > - perf stat -M "$m" -a true > > + result=$(perf stat -M "$m" -a true 2>&1) > > + rc=$? > > + # Skip if there is no access to perf_events monitoring > > + # Otherwise exit based on the return code of perf comamnd. > > + if echo "$result" | grep -q "Access to performance monitoring and observability operations is limited"; > > + then > > + continue > > + else > > + [ $rc -ne 0 ] && exit $rc > > + fi > > + > > done > > > > exit 0 -- - Arnaldo