Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp754110pxb; Thu, 21 Oct 2021 08:52:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzbodipu351BSPjy+5FF4P0XEtGp8SEi63tERl4dmFBEv2P0qOA1Dzf1qtdhoksEsujw4jV X-Received: by 2002:a17:906:434f:: with SMTP id z15mr1585395ejm.180.1634831557776; Thu, 21 Oct 2021 08:52:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634831557; cv=none; d=google.com; s=arc-20160816; b=J5SREga3ogBQCcXfMmECZoVc7WGzlopgkOLXq5GB1b2rpzHkYIJayMsdd01fWAEiJ3 jh1a62bu/mPX9pdG/Mfda2Dm3PslB5mSznGP5E22jnWPU5FyUEVvGFVbQCJuHGgKRoj6 FM9krfJW6CrRIP9het+U1/WL2xkXLu+96cHW6NFOvmkOz7VX2fNyH/YYaaHhvUqIl2nx f94bEoWaFPrI3MOocaeQM5Y1Ef1kKkuRXlMu5vXCeLjfTMfwDV0V9qvMWgKkcPG0+7MM Z1sl1vYrnDXN6Lsf3h2DQWNGPts+k7zuRvOVszH57b+PSUqwooxEJ5vuFskplqNRd6lb zK1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=B1/Vs59OV/rlWJ6WA3d6EaWlhOZ3vZvbO+vUp8p6+uU=; b=XGG4UPUkKZfD0A5PonYkcs+xAPiW+6IRFsv0bJcexwpizkWhYs2ap0yj2sPZf+VR6b jJOI7+SJ1yBFkQCiiNWWBuFyvXcLDXje9unf9Uhh26kF1uX/deGpfigE66MC2JMhPiOD LDq1Ir9s92WXiih+Nd6XByc+lePYtXaOPRRPPQeZ3wAiQo3YAEmqXkyMApX90D1JzuJP tcUWv3NSf53kBgf0pRq+t7p0RZD4atKzUdUAAH2zTNuQz+FSJud1W6g4M/RAkj0JjxDh /pkUajBGSknE4agc0tfgPn0YBX5Bl5MNpYRts7dHAHHG7m3nh+VTFmfBUkYKcvhw0A+A 7MuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ZbrLEWc8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id he31si2332939ejc.285.2021.10.21.08.52.08; Thu, 21 Oct 2021 08:52:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=ZbrLEWc8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231406AbhJUPwE (ORCPT + 99 others); Thu, 21 Oct 2021 11:52:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230000AbhJUPwE (ORCPT ); Thu, 21 Oct 2021 11:52:04 -0400 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4AC1FC061764 for ; Thu, 21 Oct 2021 08:49:48 -0700 (PDT) Received: by mail-pg1-x530.google.com with SMTP id g184so695040pgc.6 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=Yy7YmGZsDHNaPaeHVMm+htn1qGeMtj0JErSubahoSyUk9FqqZHNe63aVRvhdPbGLck hskJSO+ONknjMV0iGaIuSJ3LO4VaZJ8meNUAATmCHRQimEw9cb4fDUX/vd4mzqJcMqii TWenSXmPaxS3aw3HtH7un4Lia2bpa/hZC5QvCJSXAxgzqPtaDRHhNVe+M/QHGT13Ik9+ XJ2uxvPfpA4MChjsPAs+tyL3NbE7d2uTmCMbCqsDx28Y49oD5D+s3wtd1/zas0sDXlJF Llz7cutuaLhKwSz69hpnVhWpKj1jQtL3g3vFQ7Y/oBN5zvG239owOXCfmHh71eBdGeoF +jRg== X-Gm-Message-State: AOAM530IBksFTkqqc6oC1aAvlkj/NGwZx5zs75AjdiiqHo2yeCZ2Rgpm oGV5kgaZSlpyKCDUphd29+4P0g== 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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211021134530.206216-5-leo.yan@linaro.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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