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 X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7B421C433B4 for ; Mon, 17 May 2021 19:56:46 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0E191611ED for ; Mon, 17 May 2021 19:56:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0E191611ED Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=JCcfTy9KX0cX2ueC+E3ET0OM4qi5SphWFLPvxZc6z9k=; b=rdvXvTVbAWzBzBFcuo63zSbkf0 ShBPfDyYSlTLgCNtMI/uPsU6UjA69y5xRMdR275YOU44F9a1Jjs32szl0ZPinuBH4qCuKaHN8JMk2 7Aiic9pFclPjdTOIxciUk/T9FhiXOVTAud70lhiPMdm/Msdm6MrSx19saUrMwpyx38l4dNTSVplFn iPxEhYXGawfrBp4DID8iob/Y0IYm3lDRVLMt4Q7sdOBdkPQPHyrQCwpgDBHU4wy2/oxlZltyVQVfK BFn8grT+tVQH4OWoldMriWKP2sXet2Ur5E+USeW/Z1jiwCLTThMrNhnsXrqNkzSzkU4rqP0CMC94d rm3ct7bQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lijJt-00FzIV-IA; Mon, 17 May 2021 19:54:29 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lijJc-00FzFg-Rj for linux-arm-kernel@desiato.infradead.org; Mon, 17 May 2021 19:54:13 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:In-Reply-To:References; bh=SMI1NGkyA9KDseWfqagnDt+aMEJhhRHqdf6sB+Zl3RY=; b=J2NDC43Y11A4i5Dfc5Aqt0Ay5s WPcXBgikxLDEpfn9qq75S5Es1LIJPhy3wmqYeYKPVXeVTRTAMTW8/7rcsKr+OpL8I/9pMXN9FJiiK kxoRGzRUmLKaQxjEnu6TZsFsqiJVbIyoUP4CssA1pl7uYZCGINieQOmNNR8P+0jPV6AQ5pwXeRcw8 LSYd0WiIgAGV3nUMeCb86ZIyFMzdnd0JkFWvFuoMIRlhmsW3ZAQ5G4+0QTUw1WiRiV2YTEaNfawoG dLtmnEaF3lhWi6R6YRkR0q3qc8j6dp4lD4OwnPsZe27d8FcyYszQQ4y+NFc3cjWIil628NoiZRSF4 PoLtWNRg==; Received: from mail-ot1-f46.google.com ([209.85.210.46]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lijJZ-00E6Yb-P8 for linux-arm-kernel@lists.infradead.org; Mon, 17 May 2021 19:54:11 +0000 Received: by mail-ot1-f46.google.com with SMTP id t10-20020a05683022eab0290304ed8bc759so6589455otc.12 for ; Mon, 17 May 2021 12:54:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=SMI1NGkyA9KDseWfqagnDt+aMEJhhRHqdf6sB+Zl3RY=; b=YKoWWdjSjH/uKFHzorhuwP8yVCjB63NUd8jQ19a6m/FVLlzFXJYSuNWlAPgX5qib4e CnUEiAQ6ul6hbposDTcoXJxzT6fIRCkYG14sBFhTyYnESsSukVn/S3SVwtWA53thW/ic 7//pKrYObU1xripxFggd3is133QEhl/nge5LPeg72Pc7/8PzDdelF3TlBWIpJy+xZ/gB pTo+o/3/443n26KZcPHhFZYqsJ+91iusZQP8sNj1ijlTL3SaFIXBssdApH9g4Lhwzg97 4NN1wMwVItp5etXln/WIgR5hwi/PAUTjkwl8t9uAcFM0h7Dct4YnUiNNP72JAj3Pw+aL 3Aug== X-Gm-Message-State: AOAM532wNXgP51/lY1DGTgDL9N+l+Zo1a/mjpUVLIDf/U1KJgrTM9Y3r dcqqhteOI0HYiL6XY3xw9A== X-Google-Smtp-Source: ABdhPJyFrWyrEN7G2NNq23CHUzxxCHwIuIUMabui/qfH19Yl2FvJaX0moj81sOdSqqc7Wszj/9EnTQ== X-Received: by 2002:a9d:4584:: with SMTP id x4mr1002973ote.85.1621281247451; Mon, 17 May 2021 12:54:07 -0700 (PDT) Received: from xps15.herring.priv (24-155-109-49.dyn.grandenetworks.net. [24.155.109.49]) by smtp.googlemail.com with ESMTPSA id m81sm2920758oig.43.2021.05.17.12.54.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 May 2021 12:54:06 -0700 (PDT) From: Rob Herring To: Will Deacon , Catalin Marinas , Peter Zijlstra , Ingo Molnar , Mark Rutland Cc: Arnaldo Carvalho de Melo , Jiri Olsa , Kan Liang , Ian Rogers , Alexander Shishkin , honnappa.nagarahalli@arm.com, Zachary.Leaf@arm.com, Raphael Gault , Jonathan Cameron , Namhyung Kim , Itaru Kitayama , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v8 0/5] arm64 userspace counter support Date: Mon, 17 May 2021 14:54:00 -0500 Message-Id: <20210517195405.3079458-1-robh@kernel.org> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210517_125409_859831_1BE53E8A X-CRM114-Status: GOOD ( 26.82 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Another version of arm64 userspace counter access support. This is just the Arm bits as Arnaldo asked to send the tools separately. The bulk of the libperf changes landed in 5.13-rc1. This version departs from the x86 implementation by requiring the user to always explicitly request user access (via attr.config1) and only enables access for task bound events. Rather than trying to lock down the access as the x86 implementation has been doing, we can start with only a limited use case enabled and later expand it if needed. This originally resurrected Raphael's series[1] to enable userspace counter access on arm64. My previous versions are here[2][3][4][5][6][7][8]. A git branch is here[9]. Changes in v8: - Restrict user access to thread bound events which simplifies the implementation. A couple of perf core changes (patches 1 and 2) are needed to do this. - Always require the user to request userspace access. Changes in v7: - Handling of dirty counter leakage and reworking of context switch and user access enabling. The .sched_task hook and undef instruction handler are now utilized. (Patch 3) - Add a userspace disable switch like x86. (Patch 5) Changes in v6: - Reworking of the handling of 64-bit counters and user access. There's a new config1 flag to request user access. This takes priority over the 64-bit flag and the user will get the maximum size the h/w supports without chaining. - The libperf evsel mmap struct is stored in its own xyarray - New tests for user 64-bit and 32-bit counters - Rebase to v5.12-rc2 Changes in v5: - Limit enabling/disabling access to CPUs associated with the PMU (supported_cpus) and with the mm_struct matching current->active_mm. The x86 method of using mm_cpumask doesn't work for arm64 as it is not updated. - Only set cap_user_rdpmc if event is on current cpu. See patch 2. - Create an mmap for every event in an evsel. This results in some changes to the libperf mmap API from the last version. - Rebase to v5.11-rc2 Changes in v4: - Dropped 'arm64: pmu: Add hook to handle pmu-related undefined instructions'. The onus is on userspace to pin itself to a homogeneous subset of CPUs and avoid any aborts on heterogeneous systems, so the hook is not needed. - Make perf_evsel__mmap() take pages rather than bytes for size - Fix building arm64 heterogeneous test. Changes in v3: - Dropped removing x86 rdpmc test until libperf tests can run via 'perf test' - Added verbose prints for tests - Split adding perf_evsel__mmap() to separate patch The following changes to the arm64 support have been made compared to Raphael's last version: The major change is support for heterogeneous systems with some restrictions. Specifically, userspace must pin itself to like CPUs, open a specific PMU by type, and use h/w specific events. The tests have been reworked to demonstrate this. Chained events are not supported. The problem with supporting chained events was there's no way to distinguish between a chained event and a native 64-bit counter. We could add some flag, but do self monitoring processes really need that? Native 64-bit counters are supported if the PMU h/w has support. As there's already an explicit ABI to request 64-bit counters, userspace can request 64-bit counters and if user access is not enabled, then it must retry with 32-bit counters. Prior versions broke the build on arm32 (surprisingly never caught by 0-day). As a result, event_mapped and event_unmapped implementations have been moved into the arm64 code. There was a bug in that pmc_width was not set in the user page. The tests now check for this. The documentation has been converted to rST. I've added sections on chained events and heterogeneous. Rob [1] https://lore.kernel.org/r/20190822144220.27860-1-raphael.gault@arm.com/ [2] https://lore.kernel.org/r/20200707205333.624938-1-robh@kernel.org/ [3] https://lore.kernel.org/r/20200828205614.3391252-1-robh@kernel.org/ [4] https://lore.kernel.org/r/20200911215118.2887710-1-robh@kernel.org/ [5] https://lore.kernel.org/r/20201001140116.651970-1-robh@kernel.org/ [6] https://lore.kernel.org/r/20210114020605.3943992-1-robh@kernel.org/ [7] https://lore.kernel.org/r/20210311000837.3630499-1-robh@kernel.org/ [8] https://lore.kernel.org/r/20210420031511.2348977-1-robh@kernel.org/ [9] git://git.kernel.org/pub/scm/linux/kernel/git/robh/linux.git arm64-user-perf-event-v8 Kan Liang (1): perf: Track per-PMU sched_task() callback users Raphael Gault (1): Documentation: arm64: Document PMU counters access from userspace Rob Herring (3): perf: Add a counter for number of user access events in context arm64: perf: Enable PMU counter userspace access for perf event arm64: perf: Add userspace counter access disable switch Documentation/arm64/perf.rst | 68 ++++++++++- arch/arm64/kernel/perf_event.c | 201 +++++++++++++++++++++++++++++++-- include/linux/perf/arm_pmu.h | 11 +- include/linux/perf_event.h | 4 + kernel/events/core.c | 8 +- 5 files changed, 279 insertions(+), 13 deletions(-) -- 2.27.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel