From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1E78D567E for ; Tue, 15 Aug 2023 06:32:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 829BAC433C8; Tue, 15 Aug 2023 06:32:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692081155; bh=gX4mUsVyiwiQm7PAb3hyxRoJKQABWyQbLBTieIzG3YU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=sVgD0LQS3KIOPswacqqAKmylw89V2v6yvOOScQTXvpq7mHiDxTxvUrHxPqf5ijV6M MKyscoB8cEiKlogktnu1EU5no/v+26rNtcGENPAVkno75NHx8DPkBzvYCKB8eVsD/M BPhe/ONQwGrMGXAJQ4i/q9VKvQhfTZ/t3TLc6ZQnOQmvHBc+o5aaYAqfG30FJ/X4JU 5Mf35qhAektal00hU3yopWh++2kZLbP3R6WIkkk50QtDfLA2kb4qKTceIg4kxrWTCn heqNKwhcNLCnGHHlsyyri/xl3zF/zSV8KMqnN0amWtAvCkrJ0q+pxR/5d1t3FXjxDw VX1lKyiwOO8Vg== Received: from [194.182.8.86] (helo=wait-a-minute.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1qVnbV-004u5j-6Z; Tue, 15 Aug 2023 07:32:33 +0100 Date: Tue, 15 Aug 2023 07:32:40 +0100 Message-ID: <87leecq0hj.wl-maz@kernel.org> From: Marc Zyngier To: Leo Yan Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, James Morse , Suzuki K Poulose , Oliver Upton , Zenghui Yu , Huang Shijie , Mark Rutland , Will Deacon Subject: Re: [PATCH] KVM: arm64: pmu: Resync EL0 state on counter rotation In-Reply-To: <20230814071627.GA3963214@leoy-huanghe> References: <20230811180520.131727-1-maz@kernel.org> <20230814071627.GA3963214@leoy-huanghe> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/28.2 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) Precedence: bulk X-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 194.182.8.86 X-SA-Exim-Rcpt-To: leo.yan@linaro.org, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, kvm@vger.kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.com, shijie@os.amperecomputing.com, mark.rutland@arm.com, will@kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false On Mon, 14 Aug 2023 08:16:27 +0100, Leo Yan wrote: > > On Fri, Aug 11, 2023 at 07:05:20PM +0100, Marc Zyngier wrote: > > Huang Shijie reports that, when profiling a guest from the host > > with a number of events that exceeds the number of available > > counters, the reported counts are wildly inaccurate. Without > > the counter oversubscription, the reported counts are correct. > > > > Their investigation indicates that upon counter rotation (which > > takes place on the back of a timer interrupt), we fail to > > re-apply the guest EL0 enabling, leading to the counting of host > > events instead of guest events. > > Seems to me, it's not clear for why the counter rotation will cause > the issue. Maybe unclear to you, but rather clear to me (and most people else on Cc). > > In the example shared by Shijie in [1], the cycle counter is enabled > for both host and guest No. You're misreading the example. We're profiling the guest from the host, and the guest has no PMU access. > and cycle counter is a dedicated event > which does not share counter with other events. Even there have > counter rotation, it should not impact the cycle counter. Who says that we're counting cycles using the cycle counter? This is an event like any other, and it can be counted on any counter. > > I mean if we cannot explain clearly for this part, we don't find the > root cause, and this patch (and Shijie's patch) just walks around the > issue. We have the root cause. You just need to think a bit harder. M. -- Without deviation from the norm, progress is not possible.