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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6564EC433F5 for ; Thu, 21 Oct 2021 15:51:15 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 375B960D42 for ; Thu, 21 Oct 2021 15:51:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 375B960D42 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=JvdwdxpQIwUGHQvfPyfsyizPuLpq+0Kw0gQzC7O0FP4=; b=FCDXc8Q2nbYD62 nhJJ0Ec1+vgOVNRFVb3HIKrhh24i+3QrVWvC3n0dGWnWKBoVXuYdycNDXL/9HhHfXtvIGIjzJKFKr FpC3OOZztCcsccF+D3BoTMnz0LeZKCKHcO0dx5tStRQpnLKzFJh6J74Cu4vzLUO4sEpXL4nxZ3/cS RDek6g4CBB3QtC7gaaxV+y5sDt5xn0OK6Qp6g0TMCcBnVZOfy+cVAdhq5bfXcR77/59PR5fbfUOHH ux8FV+g8sNX2s/lg6/eqKROsCFJZpwHqqdUM6DDsp+SLnoiILrYw2CsYk+HYhc9DHC/O0MojmruvZ qG+xAO1WOrfe0T5Gev0g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mdaKK-008EB1-NY; Thu, 21 Oct 2021 15:49:56 +0000 Received: from mail-pg1-x52e.google.com ([2607:f8b0:4864:20::52e]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mdaKG-008E8R-DF for linux-arm-kernel@lists.infradead.org; Thu, 21 Oct 2021 15:49:53 +0000 Received: by mail-pg1-x52e.google.com with SMTP id q187so711748pgq.2 for ; Thu, 21 Oct 2021 08:49:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=B1/Vs59OV/rlWJ6WA3d6EaWlhOZ3vZvbO+vUp8p6+uU=; b=ZbrLEWc8XCHfsf9wt1aDQHxFzTJ8rEsxaTYPDKBbrRupbVWpHtTCPlV/ZHjauRl9rY qqkbRN9u2kl4MJlEwsbw0rYEHrGvH+9pp2aqwMMD7r6fnoNhZFk1foo8lO7382V3WVGC 0FbbFl888tBrxihLXPYLfXAufTVIgRjw+nugY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=B1/Vs59OV/rlWJ6WA3d6EaWlhOZ3vZvbO+vUp8p6+uU=; b=Z95av0jBfroTWIzIl1+2wmXFErNykZdJ+l5N95AbFpUSUQyitSvEoxFU8ANBMrRnu6 flmh2dprPl6eqiupfdrdt/k9yP6z7447ryV8T9TrQH2/F5nHlBZEhYZS9YFrUwUcYOh8 LeI4IBGcE5RIKMIV0N4uRrRdsffHfa0RKL/n0HrAs2QrtJzxq4LZaam88bCJltAG0b4o d8INwnc2GC/0RLZ/EQBGf8Gw4C7+szk/3Is81zRE1xkfbfd5E2H+0W+WfKpMzu3sBvJz HQ33yeRtI6/iy4YExf4Tp4SoFsB0/XpwLdJFR+p08XgVRJ2R3VtaSpbc+pD6OblcYo0c AXvw== X-Gm-Message-State: AOAM532Lw7880N+J7NTqdt8aa59Khz1cq0iG7I2qDAliX9eHQGA1PMKa O7/tVrcPhA+4g3+WOKkZMQjzsA== X-Google-Smtp-Source: ABdhPJw+9J2A0sNBhnV+GqqNjnX5G4VuuTqU8s7+dkEe3eTfgQVYMCUKYcJCcnwHJb/H4t3RMrJRHQ== X-Received: by 2002:a62:1596:0:b0:44c:f7b3:df74 with SMTP id 144-20020a621596000000b0044cf7b3df74mr6803173pfv.60.1634831387812; Thu, 21 Oct 2021 08:49:47 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id z12sm9595637pjh.51.2021.10.21.08.49.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Oct 2021 08:49:47 -0700 (PDT) Date: Thu, 21 Oct 2021 08:49:46 -0700 From: Kees Cook To: Leo Yan Cc: Catalin Marinas , Will Deacon , Mark Rutland , Ard Biesheuvel , Sami Tolvanen , Nicholas Piggin , James Morse , Marc Zyngier , Joey Gouly , Peter Collingbourne , Vincenzo Frascino , "Peter Zijlstra (Intel)" , Stephane Eranian , James Clark , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [RFCv1 4/4] perf: arm_spe: Dynamically switch PID tracing to contextidr Message-ID: <202110210848.35971643C6@keescook> References: <20211021134530.206216-1-leo.yan@linaro.org> <20211021134530.206216-5-leo.yan@linaro.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20211021134530.206216-5-leo.yan@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211021_084952_463849_A4F4DD55 X-CRM114-Status: GOOD ( 24.46 ) 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 On Thu, Oct 21, 2021 at 09:45:30PM +0800, Leo Yan wrote: > Now Arm64 provides API for enabling and disable PID tracing, Arm SPE > driver invokes these functions to dynamically enable it during > profiling when the program runs in root PID name space, and disable PID > tracing when the perf event is stopped. > > Device drivers should not depend on CONFIG_PID_IN_CONTEXTIDR for PID > tracing, so this patch uses the consistent condition for setting bit > EL1_CX for PMSCR. My own preference here would be to not bother with the new enable/disable helpers, but just open code it right here. (Save a patch and is the only user.) But I defer to the taste of arm64 maintainers. :) -Kees > > Signed-off-by: Leo Yan > --- > drivers/perf/arm_spe_pmu.c | 13 ++++++++++++- > 1 file changed, 12 insertions(+), 1 deletion(-) > > diff --git a/drivers/perf/arm_spe_pmu.c b/drivers/perf/arm_spe_pmu.c > index d44bcc29d99c..935343cdcb39 100644 > --- a/drivers/perf/arm_spe_pmu.c > +++ b/drivers/perf/arm_spe_pmu.c > @@ -23,6 +23,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -272,7 +273,7 @@ static u64 arm_spe_event_to_pmscr(struct perf_event *event) > if (!attr->exclude_kernel) > reg |= BIT(SYS_PMSCR_EL1_E1SPE_SHIFT); > > - if (IS_ENABLED(CONFIG_PID_IN_CONTEXTIDR) && perfmon_capable()) > + if (perfmon_capable() && (task_active_pid_ns(current) == &init_pid_ns)) > reg |= BIT(SYS_PMSCR_EL1_CX_SHIFT); > > return reg; > @@ -731,6 +732,13 @@ static void arm_spe_pmu_start(struct perf_event *event, int flags) > if (hwc->state) > return; > > + /* > + * Enable tracing PID to contextidr if profiling program runs in > + * root PID namespace. > + */ > + if (perfmon_capable() && (task_active_pid_ns(current) == &init_pid_ns)) > + contextidr_enable(); > + > reg = arm_spe_event_to_pmsfcr(event); > write_sysreg_s(reg, SYS_PMSFCR_EL1); > > @@ -792,6 +800,9 @@ static void arm_spe_pmu_stop(struct perf_event *event, int flags) > } > > hwc->state |= PERF_HES_STOPPED; > + > + if (perfmon_capable() && (task_active_pid_ns(current) == &init_pid_ns)) > + contextidr_disable(); > } > > static int arm_spe_pmu_add(struct perf_event *event, int flags) > -- > 2.25.1 > -- Kees Cook _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel