Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp2693066rwl; Thu, 13 Apr 2023 09:35:08 -0700 (PDT) X-Google-Smtp-Source: AKy350ZvqXFOgHFaxVRynHlIDumCgu+YxZMxRSKDxQUdelCOQ6GQHc9HFJGLNvO96VX6D6k10BLE X-Received: by 2002:a05:6a00:180d:b0:638:7e00:48c4 with SMTP id y13-20020a056a00180d00b006387e0048c4mr4062556pfa.21.1681403708023; Thu, 13 Apr 2023 09:35:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681403708; cv=none; d=google.com; s=arc-20160816; b=D93by2s6mpmKyK70vMKxcCBj6WjMsWwCrCtqqk/uzH1BgkuBhdJvkPz9tek7WCJ48s TqhiEceHmW8xys0EFiBqQ959otP4pHOtWp7tzAI2YMsAvBdvAxulYRrhTIwtcZG2/M/4 AR1OvXe7grLpqeNEv1b7pxIRekZTEDLmR8ydfwnXngrvdjhfO/fefTqdgbzopqItLIj1 grYW0XlwcFjejhDmlXrgQrRyw5eNecg91pux/crLzv6cKzzCoDWim2vhJu4jzmrJRwZW mM9DABVGVjln6htBCLqEv+IsJIYpDQD0GvERo0egkbr/NIAnVauTW/3sf02k9r/xyMqk 8YWQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=38Yb3K2X39JYdroVCYnZn1iH0zsgOPm1opWg6u9OrnA=; b=xl/+U6KxVZKxCbxC+X/NiFogXX5jeq29zR25ppzxaDvC0oUM6EtMfgl2lHprGdOoZz 6TRRSd+eRaXkOgp1r21eCKbg6a1baQID0JimQ0WOeMuulS0K04gcX4DO8RbW+adEFkmJ V4zRM2K86UAxonuQpafFaW780oGtLYdfwX7657bZXZ3nzlw1Qxk4jQuKlDoCbkIN/ydj zGqxWzUIpJ2Dhy62TM1y8qo2+tFySoq67AA8kvrIeETowyCXQXHvZPuR+yJNZPHkz694 P9itwj9v9bNw7VsNHiYOr4jdJiyce7FK3HDGP12j5bK1EQztrp6jDg6Z5bt/TZfPARuL YHcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=FYMc15O2; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f8-20020aa79688000000b0062ae6345c6dsi2018791pfk.392.2023.04.13.09.34.43; Thu, 13 Apr 2023 09:35:08 -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=@rivosinc-com.20221208.gappssmtp.com header.s=20221208 header.b=FYMc15O2; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229990AbjDMQRf (ORCPT + 99 others); Thu, 13 Apr 2023 12:17:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229597AbjDMQRe (ORCPT ); Thu, 13 Apr 2023 12:17:34 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D288F9759 for ; Thu, 13 Apr 2023 09:17:31 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id v10so2277751wmn.5 for ; Thu, 13 Apr 2023 09:17:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1681402650; x=1683994650; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=38Yb3K2X39JYdroVCYnZn1iH0zsgOPm1opWg6u9OrnA=; b=FYMc15O2+ikuHwDZXewujBymuKjb0wLG3G9POi/bxOvkCAVqfUklYRLX0godmEWGyl Mb0djbmpWZ0hLSRiWdLcrBCLV45eQOqDXCa0Nc2vK5NzWC60U92C3lcWGqlYAXV/KtCQ rCqtnkk3YhyRaaoUwTApDJTHO7XmmgvmhppYk+Dlp8WGbqjPYJPws+iIgqZTOLr5qqxA ICXBCUnEN9BY+gBFYb06nnH6hPPOnmzEqivs0CbguiSY4J1A6j5dGec27xGTfZ2nKqbp 76aOt1t7EtPrYCm14ndD5tk1sxdtnsLnaaLtQ2NHqC8XWn1I6tX1sRe0BuacrDD9WZRx hJ2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681402650; x=1683994650; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=38Yb3K2X39JYdroVCYnZn1iH0zsgOPm1opWg6u9OrnA=; b=asPal1mCKC7Wa6+3td8oSvMX2rjdNcpl8RIgcXRiulWWbDjhQds2YzlDP4U96PO1ag 6n3y2bXn4IPNlBgZ1QdlbXw+tmJ09YGZMBbtbiY6JFfCQ01sKQbxtI2tInwRN+bpP1Sl /jdxanJkE0IPlf96WcSw7/Zwo+s/vGVHMBGBLu98DWIMMO1GWt539HGZ8LgXLwb9tTOG D93pg5LWkQ+KT30orUOOkUF7jpKxVv/LrAYzFL0beFLiU9Tnz+SegoLyfPA90PnwX4DG TSZzxQ6y2MG8CY/uKE8JQLMga1lQGul85dsYXVEjIT0WD4+PvBceMmOlkevZ5prjAw40 jRbA== X-Gm-Message-State: AAQBX9cg6BDcKmJvAoWgvRfCm/D5p7/yBL9gWzbzp7U2tJgSBzOPpDcD 3G+Mba1p9RAYnBLKAwpLSYbP3w== X-Received: by 2002:a1c:6a14:0:b0:3f0:7db5:607a with SMTP id f20-20020a1c6a14000000b003f07db5607amr2179470wmc.33.1681402650384; Thu, 13 Apr 2023 09:17:30 -0700 (PDT) Received: from alex-rivos.ba.rivosinc.com (amontpellier-656-1-456-62.w92-145.abo.wanadoo.fr. [92.145.124.62]) by smtp.gmail.com with ESMTPSA id w16-20020a05600c475000b003f092f0e0a0sm9350624wmo.3.2023.04.13.09.17.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Apr 2023 09:17:30 -0700 (PDT) From: Alexandre Ghiti To: Jonathan Corbet , Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , Ian Rogers , Paul Walmsley , Palmer Dabbelt , Albert Ou , Atish Patra , Anup Patel , Will Deacon , Rob Herring , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org Cc: Alexandre Ghiti Subject: [PATCH 0/4] riscv: Allow userspace to directly access perf counters Date: Thu, 13 Apr 2023 18:17:21 +0200 Message-Id: <20230413161725.195417-1-alexghiti@rivosinc.com> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,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 riscv used to allow direct access to cycle/time/instret counters, bypassing the perf framework, this patchset intends to allow the user to mmap any counter when accessed through perf. But we can't break the existing behaviour so we introduce a sysctl perf_user_access like arm64 does, which defaults to the legacy mode described above. The core of this patchset lies in patch 4, the first 3 patches are simple fixes. base-commit-tag: v6.3-rc1 Alexandre Ghiti (4): perf: Fix wrong comment about default event_idx include: riscv: Fix wrong include guard in riscv_pmu.h riscv: Make legacy counter enum match the HW numbering riscv: Enable perf counters user access only through perf Documentation/admin-guide/sysctl/kernel.rst | 23 +++- arch/riscv/include/asm/perf_event.h | 3 + arch/riscv/kernel/Makefile | 2 +- arch/riscv/kernel/perf_event.c | 65 +++++++++++ drivers/perf/riscv_pmu.c | 42 ++++++++ drivers/perf/riscv_pmu_legacy.c | 24 ++++- drivers/perf/riscv_pmu_sbi.c | 113 ++++++++++++++++++-- include/linux/perf/riscv_pmu.h | 9 +- include/linux/perf_event.h | 3 +- tools/lib/perf/mmap.c | 65 +++++++++++ 10 files changed, 332 insertions(+), 17 deletions(-) create mode 100644 arch/riscv/kernel/perf_event.c -- 2.37.2