From patchwork Fri Sep 8 20:13:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Huang X-Patchwork-Id: 9944979 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1543D604D4 for ; Fri, 8 Sep 2017 20:13:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0E962288F8 for ; Fri, 8 Sep 2017 20:13:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0398F288FA; Fri, 8 Sep 2017 20:13:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9910B288F9 for ; Fri, 8 Sep 2017 20:13:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757078AbdIHUNP (ORCPT ); Fri, 8 Sep 2017 16:13:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36978 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757063AbdIHUNO (ORCPT ); Fri, 8 Sep 2017 16:13:14 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 111E57E429 for ; Fri, 8 Sep 2017 20:13:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 111E57E429 Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=wei@redhat.com Received: from weilaptop.redhat.com (ovpn-124-22.rdu2.redhat.com [10.10.124.22]) by smtp.corp.redhat.com (Postfix) with ESMTP id 865EB5D964; Fri, 8 Sep 2017 20:13:13 +0000 (UTC) From: Wei Huang To: kvm@vger.kernel.org Cc: rkrcmar@redhat.com, pbonzini@redhat.com Subject: [kvm-unit-tests PATCH 1/1] x86/pmu: change the num_counters to reflect the real gp counters Date: Fri, 8 Sep 2017 15:13:12 -0500 Message-Id: <1504901592-10357-1-git-send-email-wei@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 08 Sep 2017 20:13:14 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently pmu.c sets num_counters to MIN(num_gp_counters, num_gp_events). This is to prevent the out-of-bound access to gp_events[] array in check_counters_many(). However it also means that check_counters_many() can NOT stress all gp counters if num_gp_counters > num_gp_events. This small patch changes the value of num_counters back to num_gp_counters and prevents the out-of-bound problem by using the mod function in the array access. Signed-off-by: Wei Huang --- x86/pmu.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/x86/pmu.c b/x86/pmu.c index a0238dc..b56b61e 100644 --- a/x86/pmu.c +++ b/x86/pmu.c @@ -275,7 +275,8 @@ static void check_counters_many(void) cnt[n].count = 0; cnt[n].ctr = MSR_IA32_PERFCTR0 + n; - cnt[n].config = EVNTSEL_OS | EVNTSEL_USR | gp_events[i].unit_sel; + cnt[n].config = EVNTSEL_OS | EVNTSEL_USR | + gp_events[i % ARRAY_SIZE(gp_events)].unit_sel; n++; } for (i = 0; i < edx.split.num_counters_fixed; i++) { @@ -397,8 +398,6 @@ int main(int ac, char **av) printf("Fixed counter width: %d\n", edx.split.bit_width_fixed); num_counters = eax.split.num_counters; - if (num_counters > ARRAY_SIZE(gp_events)) - num_counters = ARRAY_SIZE(gp_events); apic_write(APIC_LVTPC, PC_VECTOR);