Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp471327imw; Thu, 14 Jul 2022 05:07:45 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s6BCRPb1oiOHZOj4YGaZMpI2JI++CcxPsvi02pDZROSSDZsUyTYLC5T8AUDfXS8O4snAH5 X-Received: by 2002:a17:907:2cf5:b0:72b:7656:f162 with SMTP id hz21-20020a1709072cf500b0072b7656f162mr8145454ejc.565.1657800465352; Thu, 14 Jul 2022 05:07:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657800465; cv=none; d=google.com; s=arc-20160816; b=KYbmoN4qzal/55gFWaHggvy7QuiObtvHFXItPiiHznOaIXoh0cIVlSk5x0YD+JJ95U Svt8CY8EBmrA5WVriGoC92igtZoaq4ouCLZ5T37t2yeAlHaO8MPIOrBumMB9XWu1gRpN FEjx9VkRklpqtwYONB8QHiKWUf+GVAI6SbmFQa79HtzcjfpthejGLbOvmp4NfKwpE0im z1LbagYNxu943rIdjPHMp2DrfWXHfcjl/JnU+X7bze35yTSMvOmBfXsygyKKt8LSN6Wi LTHjhiNPHj62jRRTMVAKXHEMZvKWBNVQiC3AE9oYoUmLUt8kW/wyvqd7LllMTflO+xto Ipsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id; bh=9MadSum304+cjxfj1jY7YzRAHAdAE0B0MpumgalkeRg=; b=BOCV/r665Lp8vYfiyt7hiOCiZS2KAZ0PwVgdBiOCI6LIqpw9iS8ifZwhOU2tMAbcIG aHvZAE0EEgqc3FGsIHa25xY6b265xOBPHeIML8c83UTRNbX/+Gt0VqJbgokCgGeNeJ+B QFqIUe1/k9u/G00j79NA1PpYlGZHKekio0xxHPya3sxUtjHl9Ldqc4/BjHMCRHECXKad PVh2VKMNdJX22iw9Tq42qBZmvUcD2LXp3zIrru3TZdC7GFb6GmZcajVvr6FzTnDO/g1v PmWMqTn+Fitiy8JizeMV4KM4KkOHISeHeEvOkJOgkw26Kg6wE4m7UA9v/4w0hilboINz 5qOw== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bm20-20020a0564020b1400b0043a3801ebf9si1831231edb.327.2022.07.14.05.07.18; Thu, 14 Jul 2022 05:07:45 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237842AbiGNLKv (ORCPT + 99 others); Thu, 14 Jul 2022 07:10:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230005AbiGNLKu (ORCPT ); Thu, 14 Jul 2022 07:10:50 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 16432DF2F for ; Thu, 14 Jul 2022 04:10:49 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 149E2139F; Thu, 14 Jul 2022 04:10:49 -0700 (PDT) Received: from [10.57.43.87] (unknown [10.57.43.87]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 59E723F792; Thu, 14 Jul 2022 04:10:47 -0700 (PDT) Message-ID: Date: Thu, 14 Jul 2022 12:10:45 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH v3] drivers/perf: arm_spe: Fix consistency of SYS_PMSCR_EL1.CX To: Anshuman Khandual , linux-arm-kernel@lists.infradead.org Cc: german.gomez@arm.com, james.clark@arm.com, Will Deacon , Mark Rutland , Alexey Budankov , linux-kernel@vger.kernel.org References: <20220714061302.2715102-1-anshuman.khandual@arm.com> From: Suzuki K Poulose In-Reply-To: <20220714061302.2715102-1-anshuman.khandual@arm.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_HI,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE 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 On 14/07/2022 07:13, Anshuman Khandual wrote: > The arm_spe_pmu driver will enable SYS_PMSCR_EL1.CX in order to add CONTEXT > packets into the traces, if the owner of the perf event runs with required > capabilities i.e CAP_PERFMON or CAP_SYS_ADMIN via perfmon_capable() helper. > > The value of this bit is computed in the arm_spe_event_to_pmscr() function > but the check for capabilities happens in the pmu event init callback i.e > arm_spe_pmu_event_init(). This suggests that the value of the CX bit should > remain consistent for the duration of the perf session. > > However, the function arm_spe_event_to_pmscr() may be called later during > the event start callback i.e arm_spe_pmu_start() when the "current" process > is not the owner of the perf session, hence the CX bit setting is currently > not consistent. > > One way to fix this, is by caching the required value of the CX bit during > the initialization of the PMU event, so that it remains consistent for the > duration of the session. It uses currently unused 'event->hw.flags' element > to cache perfmon_capable() value, which can be referred during event start > callback to compute SYS_PMSCR_EL1.CX. This ensures consistent availability > of context packets in the trace as per event owner capabilities. > > Drop BIT(SYS_PMSCR_EL1_CX_SHIFT) check in arm_spe_pmu_event_init(), because > now CX bit cannot be set in arm_spe_event_to_pmscr() with perfmon_capable() > disabled. > > Cc: Will Deacon > Cc: Mark Rutland > Cc: Alexey Budankov > Cc: linux-arm-kernel@lists.infradead.org > Cc: linux-kernel@vger.kernel.org > Fixes: cea7d0d4a59b ("drivers/perf: Open access for CAP_PERFMON privileged process") TBH, this is not sufficient. The above commit simply replaced the capable() check with perfmon_capable() wrapper. The "incorrect check in the wrong task context" existed since : d5d9696b0380 ("drivers/perf: Add support for ARMv8.2 Statistical Profiling Extension"). So I would recommend using that for the Fixes tag. And any stable backports without perfmon_capable() could fallback to using capable() check, like we do in this patch, from the event_init. Otherwise, Reviewed-by: Suzuki K Poulose