Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp628715ybl; Fri, 24 Jan 2020 06:43:19 -0800 (PST) X-Google-Smtp-Source: APXvYqxvOb1NGZgUJbKe1cDQSrb2hKgByV42UYV2DWz7dphE8nMKugUOHt+K/nvnsmXWg7Twktov X-Received: by 2002:a9d:3cf:: with SMTP id f73mr2943961otf.11.1579876999052; Fri, 24 Jan 2020 06:43:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579876999; cv=none; d=google.com; s=arc-20160816; b=eKLeVzXzZu0Z1Kgnfjm7jrk7JhkdJySpVKhykq4jSEyxaXUFoe+1gzpxV+jiDOQuuR iYD4FRpvpkZH+jZSw7VCE3y9Lw37QC+VT+usX2N7D9iKbkEYDSIj4e9VF4iSF1U7MUN2 YbynVAvwV1CtD77qHbDOjVDUNyeV3VnIS7e/KMp3eHQy1OfpBI4x/OAqeZP9FQgbOBgu 1dKMb/VEbnZjgMYCiRE4MdUypR2IxtqSvksvS3hseIq26xu6C/LNSz6P4n6HGS6s0Uiw HTCmk8ZZS8uqwHQCUrerYUnK3nqIXi8rVMG4AEHKrxBxJzrqfyG1R6fs2UBKb8SkjzMI AmZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=S+xkkLcGvn4l2z374gMhccJvWqyhAjGkRVHUTmNEzYI=; b=B6iluYjo7MLa/Ex6U297F+9YrRv38xFtw5JD72s17XeP3KsTbAM2xNyWrrOj3wjQQf rTHoZekba4vzqYijf7GLHFhZ26KT+d0gt4If4dgnBFBKa84TsRY4uelLEjFhJQ1/p4a2 sTkiAZ2RuIXdBY4Bo82px2gRjbz/LaCNC6Af5QJ68w7F8yvjkEO2Aldfi8sP9sfVvUrf plObxRUMzm1WNOUUwqu9e/fuYDRPV0vMxdoUalqUlecw5brJ7OYWozg5RyF3mQ9adjrD h8EuUSezdxbT48jllTyUO+wmCX85/lwibgO29nE0wjo6G0MJBikywdMM01v2jko/3TpW tM0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gCA6bZXy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g126si2411051oib.105.2020.01.24.06.43.07; Fri, 24 Jan 2020 06:43:19 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gCA6bZXy; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389086AbgAXO0C (ORCPT + 99 others); Fri, 24 Jan 2020 09:26:02 -0500 Received: from us-smtp-2.mimecast.com ([205.139.110.61]:38834 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390008AbgAXO0A (ORCPT ); Fri, 24 Jan 2020 09:26:00 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579875959; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=S+xkkLcGvn4l2z374gMhccJvWqyhAjGkRVHUTmNEzYI=; b=gCA6bZXy5/Y8HE4csEk0UZnccpy9d0qpGHCMhyTmcdS3RJquMwASfUS0hC6l+I3nJHMW9V KG0to65p2tpbvOdqoQ+1bJAJqdrrzzKsFiQscDrdUQREhvoRyXz1FGFAYWx6DSt1+B255o jW5s4yWL6XNTEKpTUHumv48bU8QYXic= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-12-4vA9tXH4PUyVOE6thtzQvw-1; Fri, 24 Jan 2020 09:25:57 -0500 X-MC-Unique: 4vA9tXH4PUyVOE6thtzQvw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7D082800D41; Fri, 24 Jan 2020 14:25:55 +0000 (UTC) Received: from laptop.redhat.com (ovpn-116-37.ams2.redhat.com [10.36.116.37]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8528319C69; Fri, 24 Jan 2020 14:25:52 +0000 (UTC) From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, maz@kernel.org, linux-kernel@vger.kernel.org, kvmarm@lists.cs.columbia.edu Cc: andrew.murray@arm.com Subject: [PATCH 3/4] KVM: arm64: pmu: Fix chained SW_INCR counters Date: Fri, 24 Jan 2020 15:25:34 +0100 Message-Id: <20200124142535.29386-4-eric.auger@redhat.com> In-Reply-To: <20200124142535.29386-1-eric.auger@redhat.com> References: <20200124142535.29386-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org At the moment a SW_INCR counter always overflows on 32-bit boundary, independently on whether the n+1th counter is programmed as CHAIN. Check whether the SW_INCR counter is a 64b counter and if so, implement the 64b logic. Fixes: 80f393a23be6 ("KVM: arm/arm64: Support chained PMU counters") Signed-off-by: Eric Auger Signed-off-by: Marc Zyngier --- v1 -> v2: - Reorganize the kvm_pmu_software_increment() flow as suggested by Marc. At the exception I did not use kvm_pmu_get_counter_value() as it returns only the right half of the 64b counter. --- virt/kvm/arm/pmu.c | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/virt/kvm/arm/pmu.c b/virt/kvm/arm/pmu.c index 9f605e0b8dd7..560db6282137 100644 --- a/virt/kvm/arm/pmu.c +++ b/virt/kvm/arm/pmu.c @@ -477,28 +477,45 @@ static void kvm_pmu_perf_overflow(struct perf_event= *perf_event, */ void kvm_pmu_software_increment(struct kvm_vcpu *vcpu, u64 val) { + struct kvm_pmu *pmu =3D &vcpu->arch.pmu; int i; - u64 type, enable, reg; - - if (val =3D=3D 0) - return; =20 if (!(__vcpu_sys_reg(vcpu, PMCR_EL0) & ARMV8_PMU_PMCR_E)) return; =20 - enable =3D __vcpu_sys_reg(vcpu, PMCNTENSET_EL0); + /* Weed out disabled counters */ + val &=3D __vcpu_sys_reg(vcpu, PMCNTENSET_EL0); + for (i =3D 0; i < ARMV8_PMU_CYCLE_IDX; i++) { + u64 type, reg; + if (!(val & BIT(i))) continue; - type =3D __vcpu_sys_reg(vcpu, PMEVTYPER0_EL0 + i) - & ARMV8_PMU_EVTYPE_EVENT; - if ((type =3D=3D ARMV8_PMUV3_PERFCTR_SW_INCR) - && (enable & BIT(i))) { - reg =3D __vcpu_sys_reg(vcpu, PMEVCNTR0_EL0 + i) + 1; + + /* PMSWINC only applies to ... SW_INC! */ + type =3D __vcpu_sys_reg(vcpu, PMEVTYPER0_EL0 + i); + type &=3D ARMV8_PMU_EVTYPE_EVENT; + if (type !=3D ARMV8_PMUV3_PERFCTR_SW_INCR) + continue; + + /* increment this even SW_INC counter */ + reg =3D __vcpu_sys_reg(vcpu, PMEVCNTR0_EL0 + i) + 1; + reg =3D lower_32_bits(reg); + __vcpu_sys_reg(vcpu, PMEVCNTR0_EL0 + i) =3D reg; + + if (reg) /* no overflow on the low part */ + continue; + + if (kvm_pmu_pmc_is_chained(&pmu->pmc[i])) { + /* increment the high counter */ + reg =3D __vcpu_sys_reg(vcpu, PMEVCNTR0_EL0 + i + 1) + 1; reg =3D lower_32_bits(reg); - __vcpu_sys_reg(vcpu, PMEVCNTR0_EL0 + i) =3D reg; - if (!reg) - __vcpu_sys_reg(vcpu, PMOVSSET_EL0) |=3D BIT(i); + __vcpu_sys_reg(vcpu, PMEVCNTR0_EL0 + i + 1) =3D reg; + if (!reg) /* mark overflow on the high counter */ + __vcpu_sys_reg(vcpu, PMOVSSET_EL0) |=3D BIT(i + 1); + } else { + /* mark overflow on low counter */ + __vcpu_sys_reg(vcpu, PMOVSSET_EL0) |=3D BIT(i); } } } --=20 2.20.1