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 AA376EB64DD for ; Mon, 14 Aug 2023 08:47:50 +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: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=dZ54MbFWaQuPjEX0QCUzJ88S/zEcFK00sO4sy3nPB40=; b=cLKqZp7PEUODxR qj6IfohlOrCOXCHDatEANWHwUaHtkDbGVty6qz063XLeSrYKZkjwIox0vt6dZYkp+trwebtCMVbk+ zjlPbE7gAgmdSp0K0cQVBOl/4cPlh5iTnLPRte3Hwk5IdWbEhbpwR/6MZIoRAJlEN4jBksDySBmhs pi0WIVdTbFiyQ5pSn/cSOC1wT5Bge+4gO56Aeq89GfKBpspG0VG3Aw6BMeYxinyBdPl9IC1de6HdQ csp0CDtJ2mM+sH4q84PuTz45KJuBXCsCBtXOkbcDPXbzmOIsQHLS7Rh4ACdaOqXRgOlTZulm1vK6Z mszaG94/B1nEx+SO1pTw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qVTEW-00GYit-0e; Mon, 14 Aug 2023 08:47:28 +0000 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qVTES-00GYi9-2h for linux-arm-kernel@lists.infradead.org; Mon, 14 Aug 2023 08:47:26 +0000 Received: by mail-pf1-x430.google.com with SMTP id d2e1a72fcca58-6874d1c8610so2535794b3a.0 for ; Mon, 14 Aug 2023 01:47:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692002838; x=1692607638; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=PYKwbtaMp//CAdWN8SyKA1nXnFDIlEGRDpnjYmJ1fDk=; b=hbNWsFE56i3xCnyaHvsPALp53csD0RhtoCwpRxxt32sYvbBSE/2bfMocn51g2Jia1c qkn42mtrWOoO0O1yG3VOBQwxK9Vu28lBnSKHhRVjdBiL/LVFI9FGtKs1I2GLJDDv6wV/ f4t4pERGpW7VKSxafZihfuu+i2z7f+kT1yJFDVCJHmTWZsIZyZtPUitN3AXfRwT7MwXY VRy6LzCpXGsJFWiLV7U0Fi+pHiRlr6Hh8wF0tXLI7KKhuOxg9DkTNod+f5EWCQLK4LHb z41SbZDHCfpvnqm9QMPiBBqJso2Q3EYAOwQ5/dutxbBKjdfuzshXL+Fir4BzsXHBcZZ1 x1VA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692002838; x=1692607638; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=PYKwbtaMp//CAdWN8SyKA1nXnFDIlEGRDpnjYmJ1fDk=; b=AVeZJoZ91iV4WTZZHAGjsaBFcIz5limPWzT1YIbkv1BIcjI1IQ77peWpuLL6SaD803 PnDebRBVwd8sEqgRYXZ6FmVQDn5PCUsyqab14Vc0T+ftHHpe3WRHNjxQP6CpI/yuas6U XcLavqvepq8xxJ4wmpj+pXk3lMniYlthfJbRBeJ7XhcahtsF/HBgpY4V+lorhwiODPdz nrdHAzYWa5PALSR7aZ5QwBm6LIeJeuB9hb8iEC3St2rC3tBZvCfN0DRx81UG7VEOwXAP flqsNB2ELAgzHplMCbNaHatfk+5WGbJyZ5ZxNXY3FPEg3aJ0c/v/+0QlPZ230vobrBSw LkYw== X-Gm-Message-State: AOJu0YwTEaAd8c0bDKcrLyVFAwdzmaG3cNk5oJSpz96JRGuQE6oz6UCO LJgedN8Gxx7iurc4ktvPZv2e9A== X-Google-Smtp-Source: AGHT+IFRlhOXNFSqg0G5udsNG6Ftwgsd0G2n/AiH38qLErUVrfvrIfQjyAOPIm/yELCQLJwhcsm0Xg== X-Received: by 2002:a05:6a00:3925:b0:668:8596:752f with SMTP id fh37-20020a056a00392500b006688596752fmr8445682pfb.4.1692002838132; Mon, 14 Aug 2023 01:47:18 -0700 (PDT) Received: from leoy-huanghe.lan ([150.230.248.162]) by smtp.gmail.com with ESMTPSA id t14-20020aa7938e000000b00682ed27f99dsm7368544pfe.46.2023.08.14.01.47.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Aug 2023 01:47:17 -0700 (PDT) Date: Mon, 14 Aug 2023 16:47:10 +0800 From: Leo Yan To: Shijie Huang Cc: Marc Zyngier , 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 Message-ID: <20230814084710.GA69080@leoy-huanghe.lan> References: <20230811180520.131727-1-maz@kernel.org> <20230814071627.GA3963214@leoy-huanghe> <5608d22d-47c3-2a03-a3d9-ba8ec51679a3@amperemail.onmicrosoft.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <5608d22d-47c3-2a03-a3d9-ba8ec51679a3@amperemail.onmicrosoft.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230814_014724_878937_C8071561 X-CRM114-Status: GOOD ( 20.97 ) 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="iso-8859-1" Content-Transfer-Encoding: quoted-printable Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Shijie, On Mon, Aug 14, 2023 at 04:12:23PM +0800, Shijie Huang wrote: [...] > > > 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. > > = > > In the example shared by Shijie in [1], the cycle counter is enabled for > > both host and guest, 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. > = > Just take a simple case: > = > =A0=A0 perf stat -e cycles:G,cycles:H, e2,e3,e4,e5,e6,e7 .... > = > = > Assume we have 8 events, but PMU only privides 7 counters(cycle + 6 norma= l) Thanks for the detailed info, now I understand it. Seems to me, based on Marc's patch, we need to apply below change. In below code, we don't need to change the perf core code and we can resolve it as a common issue for Arm PMU drivers. diff --git a/arch/arm64/kvm/pmu.c b/arch/arm64/kvm/pmu.c index 121f1a14c829..8f9673cdadec 100644 --- a/arch/arm64/kvm/pmu.c +++ b/arch/arm64/kvm/pmu.c @@ -38,14 +38,20 @@ struct kvm_pmu_events *kvm_get_pmu_events(void) void kvm_set_pmu_events(u32 set, struct perf_event_attr *attr) { struct kvm_pmu_events *pmu =3D kvm_get_pmu_events(); + int resync; = if (!kvm_arm_support_pmu_v3() || !pmu || !kvm_pmu_switch_needed(attr)) return; = + resync =3D pmu->events_guest !=3D set; + if (!attr->exclude_host) pmu->events_host |=3D set; if (!attr->exclude_guest) pmu->events_guest |=3D set; + + if (resync) + kvm_vcpu_pmu_resync_el0(); } = /* @@ -60,6 +66,8 @@ void kvm_clr_pmu_events(u32 clr) = pmu->events_host &=3D ~clr; pmu->events_guest &=3D ~clr; + + kvm_vcpu_pmu_resync_el0(); } _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel