Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp677074ybv; Thu, 13 Feb 2020 07:36:31 -0800 (PST) X-Google-Smtp-Source: APXvYqxJ+HGltSSBnCXKTzsyRGAqY3Yj/PithhFgnrIimCiArVgAB8be8j93K82MuBBO8peDUWHA X-Received: by 2002:a54:4707:: with SMTP id k7mr3106902oik.153.1581608191385; Thu, 13 Feb 2020 07:36:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581608191; cv=none; d=google.com; s=arc-20160816; b=kKN5d0joubT4I69QzLBFjE7jtgbcJ3KyFJxrazf/mcr/vjyXs7wnGdXqZ1wzUsAlhz va+u8tIBNMxRc3STY2YVUIsr8GRLxF8DhNVBNg7jQisRdvBG6A1J6WVIX9lIopyxZp0M t6GzLtDcdIr7dlhc4+w2o0BB5CQJvLmvdXi9lIXCegeIY4S8DJwNKx/RiQavzSEj5kQ4 qR8vJaTkcVGjQkT6BszeS6Y7gi0MBR97PebscJWhPDHaFT1Gc2arAzC5cAOvGYYH6KY4 fsT7QzamOt/UZTKEHSSih9HoMb/AOb6bYSlIpme8cVo5vsCZRUF+iw3LSED8iZZX0BCy VYsg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=CTEEAf1LMwVr91mNH2hgcPFw0ZBrW08+ogxUbxY4DE4=; b=oMg25KdMjqXY7PU7Xfe+VeHft1gUXHor/ndcBducZlwWQuEG49GMCzuhkQh8PhGWZo xs9k5tTe7PovxRmkgQvHth1Ghl2LJxvoP3CZ9MZr9sho9/XF703Q/Ljrlr4LTURpwbdQ yG4ZokbCoSwqcf4JxU1944vmhmYtp5YrNC/G2uvo4X6scXSsMnaBBMtXEWNOV+L6mpvD KfJJY3mzdHAlI+Y5HPqPvJvs+j6FnNwLNBH0MMRVij8yrzvHQGsB6Xmvge75/PXQfKwU 1wW9/n9/Jtv3G0TM/P+H+4UW4CjQt4nWhtW+Ry9D0SWQ6jrOhktNGo4CLuQKYo6qMufH VGUg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=F75vBHSM; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q6si1240612oth.26.2020.02.13.07.36.18; Thu, 13 Feb 2020 07:36:31 -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=@kernel.org header.s=default header.b=F75vBHSM; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728185AbgBMPa5 (ORCPT + 99 others); Thu, 13 Feb 2020 10:30:57 -0500 Received: from mail.kernel.org ([198.145.29.99]:51580 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729461AbgBMP1h (ORCPT ); Thu, 13 Feb 2020 10:27:37 -0500 Received: from localhost (unknown [104.132.1.104]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id C6C45206DB; Thu, 13 Feb 2020 15:27:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581607656; bh=AyhCAYMCFmAmAbmoLSWttuf0ENfoysuc6lyikTyu6s8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=F75vBHSMyJi0jGqD4w8thP55R8raG/uDuPB07EA6TigtQ5Pn4sgdrZR/nsHAiEc0W 5lQ54OLOEB4KWaAJsutwOIBTMmwzCs99jMWWBJb+W4cKqySVQBvmdqPlT692FxIwNo e608Xat84c14UmrC+GXKoYxf5her94YFsamBj5Bc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Auger , Marc Zyngier Subject: [PATCH 5.4 72/96] KVM: arm64: pmu: Fix chained SW_INCR counters Date: Thu, 13 Feb 2020 07:21:19 -0800 Message-Id: <20200213151906.522641270@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200213151839.156309910@linuxfoundation.org> References: <20200213151839.156309910@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Auger commit aa76829171e98bd75a0cc00b6248eca269ac7f4f upstream. 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 Link: https://lore.kernel.org/r/20200124142535.29386-4-eric.auger@redhat.com Signed-off-by: Greg Kroah-Hartman --- virt/kvm/arm/pmu.c | 43 ++++++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 13 deletions(-) --- a/virt/kvm/arm/pmu.c +++ b/virt/kvm/arm/pmu.c @@ -480,28 +480,45 @@ static void kvm_pmu_perf_overflow(struct */ void kvm_pmu_software_increment(struct kvm_vcpu *vcpu, u64 val) { + struct kvm_pmu *pmu = &vcpu->arch.pmu; int i; - u64 type, enable, reg; - - if (val == 0) - return; if (!(__vcpu_sys_reg(vcpu, PMCR_EL0) & ARMV8_PMU_PMCR_E)) return; - enable = __vcpu_sys_reg(vcpu, PMCNTENSET_EL0); + /* Weed out disabled counters */ + val &= __vcpu_sys_reg(vcpu, PMCNTENSET_EL0); + for (i = 0; i < ARMV8_PMU_CYCLE_IDX; i++) { + u64 type, reg; + if (!(val & BIT(i))) continue; - type = __vcpu_sys_reg(vcpu, PMEVTYPER0_EL0 + i) - & ARMV8_PMU_EVTYPE_EVENT; - if ((type == ARMV8_PMUV3_PERFCTR_SW_INCR) - && (enable & BIT(i))) { - reg = __vcpu_sys_reg(vcpu, PMEVCNTR0_EL0 + i) + 1; + + /* PMSWINC only applies to ... SW_INC! */ + type = __vcpu_sys_reg(vcpu, PMEVTYPER0_EL0 + i); + type &= ARMV8_PMU_EVTYPE_EVENT; + if (type != ARMV8_PMUV3_PERFCTR_SW_INCR) + continue; + + /* increment this even SW_INC counter */ + reg = __vcpu_sys_reg(vcpu, PMEVCNTR0_EL0 + i) + 1; + reg = lower_32_bits(reg); + __vcpu_sys_reg(vcpu, PMEVCNTR0_EL0 + i) = reg; + + if (reg) /* no overflow on the low part */ + continue; + + if (kvm_pmu_pmc_is_chained(&pmu->pmc[i])) { + /* increment the high counter */ + reg = __vcpu_sys_reg(vcpu, PMEVCNTR0_EL0 + i + 1) + 1; reg = lower_32_bits(reg); - __vcpu_sys_reg(vcpu, PMEVCNTR0_EL0 + i) = reg; - if (!reg) - __vcpu_sys_reg(vcpu, PMOVSSET_EL0) |= BIT(i); + __vcpu_sys_reg(vcpu, PMEVCNTR0_EL0 + i + 1) = reg; + if (!reg) /* mark overflow on the high counter */ + __vcpu_sys_reg(vcpu, PMOVSSET_EL0) |= BIT(i + 1); + } else { + /* mark overflow on low counter */ + __vcpu_sys_reg(vcpu, PMOVSSET_EL0) |= BIT(i); } } }