Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp628732ybl; Fri, 24 Jan 2020 06:43:20 -0800 (PST) X-Google-Smtp-Source: APXvYqz0oSf1x29iROMAOSOO4ZVQ0eoQIx2Z27xowPPELKQECLsj9K891nvdQPA1r7AYSHy6hFmZ X-Received: by 2002:a9d:5918:: with SMTP id t24mr3091367oth.310.1579877000325; Fri, 24 Jan 2020 06:43:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579877000; cv=none; d=google.com; s=arc-20160816; b=Wh8qVSVKoj3346TkAO42pNxM4skruDQDtL5DaNAMAzRlKiQR10oqJDwdJwDNKXSebI GMPz7a4i9njkVlhVOh0mCwKTiPrKXEKd8xm+Y1jiP4uuojLaMrDSl4KrkJ0GwwI8SKMn PCkGTPIraE5R9Cjir0Jq1IneFsCtuq2nlOFfLu0ha153Ia4betw2dZl7td0LiUQ5baLR 5fQp2ee+/0W4leyifBYrtOZBrzseuCXZc0Qa7CXYn4H3QwVG6URunCgaWWOuS+e7kCvN QF9TPbO0Ughz1fqDsVEpNEMFINF8GCfr51HQlC0nLb5f3fMuFQIn1OuzNkYkfC8iZQkW 7OqQ== 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=BcYl7Hnv7p+sg1oHvBDUntuXOOPjc9pGbSFE7rJ89fY=; b=mIgzD8aVCOaUh/CcuPqMsTUlh0sHUNvyoF7sqGqWrdKxjBDiIpEI8JCvpbO1oCbZ2Z uWBdSWcybWCAxrCEyiWjTI/srAXeuv2GHNad3n00CblhD0U70hGo/o6XyxeDtIecsSle f+FgkujFwEpfb1yEgAyNj5XPE0y8PwDSV5ezlhHmk8epA7MMuogG2vT4+TPs+/yYbhp9 4C3MtT7FSSwlfoIgtnnvo3FBhVKiEUnOhfz1IvytYB//LFYzCTj15BVdOZtPdn2FT0gA h8Uat7p2TPBIUClXzEwDGP1V2I+p0g7BC4oAX9MldLYnexQK61vsBP+RZroYdPTt+GyX gaWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Q1lgZuCu; 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 o7si2921335otk.185.2020.01.24.06.43.08; Fri, 24 Jan 2020 06:43:20 -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=Q1lgZuCu; 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 S2388443AbgAXO0F (ORCPT + 99 others); Fri, 24 Jan 2020 09:26:05 -0500 Received: from us-smtp-delivery-1.mimecast.com ([207.211.31.120]:40063 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2392226AbgAXO0D (ORCPT ); Fri, 24 Jan 2020 09:26:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579875962; 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=BcYl7Hnv7p+sg1oHvBDUntuXOOPjc9pGbSFE7rJ89fY=; b=Q1lgZuCu1PRT1C89oBwuDG+EJom1wJCUCIkTGwDBTKiljgEoMC1ibQB7vjI+e6hHtTppyy goeU203ZJbSRKPwM1F8kt+Mp0c/9pVwqZVfA4La6Tjg2Vi8Xg1SeIs+VFIuY9/Zn9dW6hG O1BIFmgT91vc16PEwaLBiz0XtHOOrRQ= 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-325-n7u0JYvMN36UujCAySSk7w-1; Fri, 24 Jan 2020 09:26:01 -0500 X-MC-Unique: n7u0JYvMN36UujCAySSk7w-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 6DCF4477; Fri, 24 Jan 2020 14:25:59 +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 4492A19C69; Fri, 24 Jan 2020 14:25:55 +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 4/4] KVM: arm64: pmu: Only handle supported event counters Date: Fri, 24 Jan 2020 15:25:35 +0100 Message-Id: <20200124142535.29386-5-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 Let the code never use unsupported event counters. Change kvm_pmu_handle_pmcr() to only reset supported counters and kvm_pmu_vcpu_reset() to only sto supported counters. Other actions are filtered on the supported counters in kvm/sysregs.c Signed-off-by: Eric Auger --- virt/kvm/arm/pmu.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/virt/kvm/arm/pmu.c b/virt/kvm/arm/pmu.c index 560db6282137..f0d0312c0a55 100644 --- a/virt/kvm/arm/pmu.c +++ b/virt/kvm/arm/pmu.c @@ -247,10 +247,11 @@ void kvm_pmu_vcpu_init(struct kvm_vcpu *vcpu) */ void kvm_pmu_vcpu_reset(struct kvm_vcpu *vcpu) { - int i; + unsigned long mask =3D kvm_pmu_valid_counter_mask(vcpu); struct kvm_pmu *pmu =3D &vcpu->arch.pmu; + int i; =20 - for (i =3D 0; i < ARMV8_PMU_MAX_COUNTERS; i++) + for_each_set_bit(i, &mask, 32) kvm_pmu_stop_counter(vcpu, &pmu->pmc[i]); =20 bitmap_zero(vcpu->arch.pmu.chained, ARMV8_PMU_MAX_COUNTER_PAIRS); @@ -527,10 +528,9 @@ void kvm_pmu_software_increment(struct kvm_vcpu *vcp= u, u64 val) */ void kvm_pmu_handle_pmcr(struct kvm_vcpu *vcpu, u64 val) { - u64 mask; + unsigned long mask =3D kvm_pmu_valid_counter_mask(vcpu); int i; =20 - mask =3D kvm_pmu_valid_counter_mask(vcpu); if (val & ARMV8_PMU_PMCR_E) { kvm_pmu_enable_counter_mask(vcpu, __vcpu_sys_reg(vcpu, PMCNTENSET_EL0) & mask); @@ -542,7 +542,7 @@ void kvm_pmu_handle_pmcr(struct kvm_vcpu *vcpu, u64 v= al) kvm_pmu_set_counter_value(vcpu, ARMV8_PMU_CYCLE_IDX, 0); =20 if (val & ARMV8_PMU_PMCR_P) { - for (i =3D 0; i < ARMV8_PMU_CYCLE_IDX; i++) + for_each_set_bit(i, &mask, 32) kvm_pmu_set_counter_value(vcpu, i, 0); } } --=20 2.20.1