Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp892574ybl; Wed, 4 Dec 2019 12:46:26 -0800 (PST) X-Google-Smtp-Source: APXvYqxkmL41kTIdwOMmUd0B42OvcmaTICvsadPLYmNiCKyvwh1UX/WDWp3azAwjW4S4440fXbM6 X-Received: by 2002:a05:6830:11d3:: with SMTP id v19mr4113517otq.322.1575492386176; Wed, 04 Dec 2019 12:46:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575492386; cv=none; d=google.com; s=arc-20160816; b=yWPxlUmMDFTmF+Yx25Y8qJ7dw0BW8oaRCWjaaGFb/J89caGwrmRxzjukxbnUnUz5iJ Akz5D57P4iFzyl6JxGGz0OUSrCCjvrQiWzgQdl9pgSeLF1bRkCOUL/qnbZFeABwx265V YBBpTKJ9SiZyLJIqXST3IRU+oQk5tbMILLUQssCTkCZwNaFa0EjQJtD+/LVteDlQBZsn OXKMl+aTjZ4J7VocopswwKJVDL9mogO1jdVpLjqc0PErFTmo2/LzNbw2io1xbEWrh4d+ OVrGt3fTgXfPFVjDwndJN+thnuV1pGT0C7J1TgrJQ4JKs+TMIW7sW8a4XJcOxh4wP2zc /Q5g== 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=1HSSxylw+ml72S+tggNSNZjvCbGfb9EILB6DT2G4aGg=; b=HM6k1jRAX7z26unu8Na0SWwMqOwXVgryHWYMxeFBfRmAS8OButxx3vZITUxj+c4S5V Y7eAEic822sWPjCDGkREJJGXZ6G7nChC1/WH3JMuLqJ0H7g+bjPW3Gr7efBdkgpiDC1G Y/47Ia4tVDj+uvviCDHl6LUl6Ez8mY2q/XB2ACRcoHlqpeSxOyBvHLA9CDlDDLq5Ob5k Y23UoHPNaE4/hZWRkDNyyX/ejIDfuyi4AtITQjuKYJv5H2k7a69dp9Y0NKu2Cj3EhrSN bgYhYsPOoqoLY4n6ehsUY7e46om/DWIVifuhKq6Af/Nvwfz7J2T/dlHMCOHdvkLbRSqO N6SQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=HzLtdA3k; 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 q7si3792270otg.238.2019.12.04.12.46.14; Wed, 04 Dec 2019 12:46:26 -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=HzLtdA3k; 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 S1728344AbfLDUoy (ORCPT + 99 others); Wed, 4 Dec 2019 15:44:54 -0500 Received: from us-smtp-delivery-1.mimecast.com ([205.139.110.120]:34183 "EHLO us-smtp-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727911AbfLDUoy (ORCPT ); Wed, 4 Dec 2019 15:44:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1575492292; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1HSSxylw+ml72S+tggNSNZjvCbGfb9EILB6DT2G4aGg=; b=HzLtdA3kQ49KuyG1St4386WLneAJXgpVdPDiBdlBJLTik8qk+nwlppIUXcDOynSgCkDy8m yj+RcsyZG/mWJsVnIio4orveN5m8KGFyGpxjny8HDOSeo546ew0dHL9YNHASZ7SzsvX/uG PnNXyjE+5rgQJGzkZhlYEYPaGUWpWVU= 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-228-mZ8JF3-HOMaWnAVM9fm54Q-1; Wed, 04 Dec 2019 15:44:51 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 54E4D1005502; Wed, 4 Dec 2019 20:44:50 +0000 (UTC) Received: from laptop.redhat.com (ovpn-116-117.ams2.redhat.com [10.36.116.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9C9C869192; Wed, 4 Dec 2019 20:44:47 +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: james.morse@arm.com, andrew.murray@arm.com, suzuki.poulose@arm.com, drjones@redhat.com Subject: [RFC 3/3] KVM: arm64: pmu: Enforce PMEVTYPER evtCount size Date: Wed, 4 Dec 2019 21:44:26 +0100 Message-Id: <20191204204426.9628-4-eric.auger@redhat.com> In-Reply-To: <20191204204426.9628-1-eric.auger@redhat.com> References: <20191204204426.9628-1-eric.auger@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-MC-Unique: mZ8JF3-HOMaWnAVM9fm54Q-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org ARMv8.1-PMU supports 16-bit evtCount whereas 8.0 only supports 10 bits. On Seatlle which has an 8.0 PMU implementation, evtCount[15:10] are not read as 0, as expected. Fix that by applying a mask on the selected event that depends on the PMU version. Also remove a redundant __vcpu_sys_reg() assignment (already done in kvm_pmu_set_counter_even_type()). Signed-off-by: Eric Auger --- arch/arm64/include/asm/perf_event.h | 5 ++++- arch/arm64/include/asm/sysreg.h | 5 +++++ arch/arm64/kernel/perf_event.c | 2 +- arch/arm64/kvm/sys_regs.c | 14 ++++++++++---- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/arch/arm64/include/asm/perf_event.h b/arch/arm64/include/asm/p= erf_event.h index 2bdbc79bbd01..37ad1d654d2a 100644 --- a/arch/arm64/include/asm/perf_event.h +++ b/arch/arm64/include/asm/perf_event.h @@ -189,7 +189,10 @@ /* * PMXEVTYPER: Event selection reg */ -#define=09ARMV8_PMU_EVTYPE_MASK=090xc800ffff=09/* Mask for writable bits *= / +/* Mask for writable bits featuring 10b evtCount (ARMv8.0-PMU)*/ +#define=09ARMV8_PMU_EVTYPE_MASK=090xc80003ff +/* Mask for writable bits featuring 16b evtCount (ARMv8.1-PMU)*/ +#define ARMV8_1_PMU_EVTYPE_MASK=090xc800ffff #define=09ARMV8_PMU_EVTYPE_EVENT=090xffff=09=09/* Mask for EVENT bits */ =20 /* diff --git a/arch/arm64/include/asm/sysreg.h b/arch/arm64/include/asm/sysre= g.h index 6e919fafb43d..e01b3e3acdf6 100644 --- a/arch/arm64/include/asm/sysreg.h +++ b/arch/arm64/include/asm/sysreg.h @@ -672,6 +672,11 @@ #define ID_AA64DFR0_TRACEVER_SHIFT=094 #define ID_AA64DFR0_DEBUGVER_SHIFT=090 =20 +#define ID_AA64DFR0_PMUVER_NOT_IMPL=090x0 +#define ID_AA64DFR0_PMUVER_8_0=09=090x1 +#define ID_AA64DFR0_PMUVER_8_1=09=090x4 +#define ID_AA64DFR0_PMUVER_IMPL_DEF=090xF + #define ID_ISAR5_RDM_SHIFT=09=0924 #define ID_ISAR5_CRC32_SHIFT=09=0916 #define ID_ISAR5_SHA2_SHIFT=09=0912 diff --git a/arch/arm64/kernel/perf_event.c b/arch/arm64/kernel/perf_event.= c index e40b65645c86..d5fe56190ad3 100644 --- a/arch/arm64/kernel/perf_event.c +++ b/arch/arm64/kernel/perf_event.c @@ -425,7 +425,7 @@ static void armv8pmu_write_counter(struct perf_event *e= vent, u64 value) static inline void armv8pmu_write_evtype(int idx, u32 val) { =09armv8pmu_select_counter(idx); -=09val &=3D ARMV8_PMU_EVTYPE_MASK; +=09val &=3D ARMV8_1_PMU_EVTYPE_MASK; =09write_sysreg(val, pmxevtyper_el0); } =20 diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 46822afc57e0..8deb6485d605 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -815,11 +815,17 @@ static bool access_pmu_evcntr(struct kvm_vcpu *vcpu, static bool access_pmu_evtyper(struct kvm_vcpu *vcpu, struct sys_reg_param= s *p, =09=09=09 const struct sys_reg_desc *r) { -=09u64 idx, reg; +=09unsigned int pmuver; +=09u64 idx, reg, dfr0, evtype_mask; =20 =09if (!kvm_arm_pmu_v3_ready(vcpu)) =09=09return trap_raz_wi(vcpu, p, r); =20 +=09dfr0 =3D read_sanitised_ftr_reg(SYS_ID_AA64DFR0_EL1); +=09pmuver =3D cpuid_feature_extract_unsigned_field(dfr0, +=09=09=09=09=09=09 ID_AA64DFR0_PMUVER_SHIFT); +=09evtype_mask =3D (pmuver =3D=3D ID_AA64DFR0_PMUVER_8_0) ? +=09=09=09ARMV8_PMU_EVTYPE_MASK : ARMV8_1_PMU_EVTYPE_MASK; =09if (pmu_access_el0_disabled(vcpu)) =09=09return false; =20 @@ -842,11 +848,11 @@ static bool access_pmu_evtyper(struct kvm_vcpu *vcpu,= struct sys_reg_params *p, =09=09return false; =20 =09if (p->is_write) { -=09=09kvm_pmu_set_counter_event_type(vcpu, p->regval, idx); -=09=09__vcpu_sys_reg(vcpu, reg) =3D p->regval & ARMV8_PMU_EVTYPE_MASK; +=09=09kvm_pmu_set_counter_event_type(vcpu, +=09=09=09=09=09 p->regval & evtype_mask, idx); =09=09kvm_vcpu_pmu_restore_guest(vcpu); =09} else { -=09=09p->regval =3D __vcpu_sys_reg(vcpu, reg) & ARMV8_PMU_EVTYPE_MASK; +=09=09p->regval =3D __vcpu_sys_reg(vcpu, reg) & evtype_mask; =09} =20 =09return true; --=20 2.20.1