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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 381AAC433EF for ; Tue, 18 Jan 2022 14:06:02 +0000 (UTC) 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:Date: Message-ID:From:References:Cc:To:Subject:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=k1pKGvDtuR96CEeFiViV4YJKmydl6qksBxf95E7TTeU=; b=T/g2zqKfgmqz+PjQCLY2QBPhg2 CceiTTHumg8D06ZaItGITCZDqODHxmzxYU/puB+JsLRpU5SO56ep6rwd0PQiEkRKZVDxxk9h5MOmi 0DfyBp+aIwr+I1pfvHEjZSJLTdgFnMJ9H0rQLGDj5D6vKcSyGxiNTgJMfjjY25t/LtgGt7s8fju5f YeZcI0CveaJY6nJedxQNQM48YIP5Uml4iqYdbKl/1G8ygick7v8S11hH5rHmtJ/VbLO7srQg38FG3 N9vQXO9S8kS5UZwqiEeCLTUDv0VYwszjaWXCQSk355OR5419rl+jJ2mqNXb/Ru3fkBj0frCoU2t+F Z1lHXsSQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n9p6G-001l2Q-0t; Tue, 18 Jan 2022 14:04:40 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n9p6C-001l1h-HB for linux-arm-kernel@lists.infradead.org; Tue, 18 Jan 2022 14:04:38 +0000 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 BBDC01FB; Tue, 18 Jan 2022 06:04:32 -0800 (PST) Received: from [10.57.35.29] (unknown [10.57.35.29]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A312D3F766; Tue, 18 Jan 2022 06:04:31 -0800 (PST) Subject: Re: [RFC PATCH 1/2] perf: arm_spe: Fix consistency of PMSCR register bit CX To: Will Deacon Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, mark.rutland@arm.com, james.clark@arm.com, leo.yan@linaro.org References: <20220117124432.3119132-1-german.gomez@arm.com> <20220117124432.3119132-2-german.gomez@arm.com> <20220118100702.GB16547@willie-the-truck> From: German Gomez Message-ID: <2cb1baab-fd9c-ea20-2a09-4cd60d9d5531@arm.com> Date: Tue, 18 Jan 2022 14:04:14 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0 MIME-Version: 1.0 In-Reply-To: <20220118100702.GB16547@willie-the-truck> Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220118_060436_677053_9B88A9B5 X-CRM114-Status: GOOD ( 23.66 ) 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 Hi Will, Many thanks for your comments On 18/01/2022 10:07, Will Deacon wrote: > On Mon, Jan 17, 2022 at 12:44:31PM +0000, German Gomez wrote: >> [...] >> >> 1. Run a process in the background with capability CAP_SYS_ADMIN in CPU0. >> >> $ taskset --cpu-list 0 sudo dd if=/dev/random of=/dev/null & >> [3] 3806 >> >> 2. Begin a perf session _without_ capabilities (we shouldn't see CONTEXT packets). >> >> $ perf record -e arm_spe_0// -C0 -- sleep 1 >> $ perf report -D | grep CONTEXT >> . 0000000e: 65 df 0e 00 00 CONTEXT 0xedf el2 >> . 0000004e: 65 df 0e 00 00 CONTEXT 0xedf el2 >> . 0000008e: 65 df 0e 00 00 CONTEXT 0xedf el2 >> [...] >> >> As can be seen, the traces begin showing CONTEXT packets when the pid is >> 0xedf (3807). > So to be clear: we shouldn't be reporting these packets because 'perf' > doesn't have the right capabilities, but we evaluate that in the context of > 'dd' (running as root) and so incorrectly grant the permission. Correct? Yes, correct. My guess was that "perfmon_capable()" was being called under the assumption that it would always be evaluated in the context of 'perf'. Is that correct? > >> This happens because the pmu start callback is run when >> the current process is not the owner of the perf session, so the CX >> register bit is set. > This doesn't really seem SPE-specific to me -- the perf_allow_*() helpers > also operate implicitly on the current task. How do other PMU drivers avoid > falling into this trap? I'm not as familiar with the other PMU drivers. I quickly tried grepping something related in the cs_etm drivers as they use CONTEXTIDR as well, but couldn't find references to perfmon_capable() or similar checks. Grepping for "perf_allow_" inside of drivers doesn't yield results. There's some gpu driver that has similar perfmon_capable() checks but unlike spe, they error out if they don't pass (drivers/gpu/drm/i915/i915_perf.c). > >> One way to fix this is by caching the value of the CX bit during the >> initialization of the PMU event, so that it remains consistent for the >> duration of the session. > It doesn't feel right to stash this in 'struct arm_spe_pmu' during event > initialisation -- wouldn't that allow perf to continue creating new events > with CX set, even if the paranoid sysctl was changed dynamically? Instead, > I think it would be better if the capabilities were stash in the event > itself somehow at initialisation time. I hadn't considered this. Makes more sense to store in the perf_event or via some type of mapping in the struct spe_pmu if not possible. Do you have any idea for the former? Or an idiomatic structure from the kernel for the later? Thanks, German > > Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel