Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp4529970yba; Wed, 17 Apr 2019 13:31:38 -0700 (PDT) X-Google-Smtp-Source: APXvYqxdZ8S28y4fnjnW7tLIck+n14dmaEWK8yX8sfdNtyfnIZcr0EeP/AoGB1+F4NtQZTW1q7uD X-Received: by 2002:a17:902:a7:: with SMTP id a36mr72997528pla.111.1555533098015; Wed, 17 Apr 2019 13:31:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555533098; cv=none; d=google.com; s=arc-20160816; b=Mkqr0XyLqXQBAExzp/wOvyHDIov34hSG2avhlmlOknSwySwZsWvgNylcv0bP4tPExg 4PrQve7ntUq6yzUBmgpL3n3fqLy3HXCFfmEXeW9T1896pFtQNXmO+TJ9TXfWkc1OYoRa fdMGdoEyHCcn+TbU+W16T6cKTytCsVIrL0/pBRulE1YGRRBXxFYzAlfFokcKgV5M5+0K H0uN7E4nu06G+nLezE1hdQ/ZW669kYWKXmt1KwDTbAkT0SCHXwV5UsZDw/dTTlllELy3 co28HK7JxbvNkSCaCZ4mL+hRV4cy6ZWwYWelpBbZeuXazLWc8DHZOil+ETkBkCktKbte hdJw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id:date :subject:cc:to:from; bh=3QdJAmXDIVeONz+6Y5qkqw5JGnKEtkPWl4IvG9xS9TQ=; b=vUzFgmlwg5XS02Un8aUlC3cd1Tfdk9r5uz4hEyLSik4bsqM5D1C7aMnbWxw8DjDcCW jJMGi3wpm3FEklrA3P72vT/wywO3ckKIWMRKedzh3chBcrtEJ+/goAw1OPRhx3RfX8p8 fiz3ARSjN8QiryJnPq58xyXZZjhZr1M5imdq3fDpWTEJFAfI5SWyziTyt5QkHgWgTEN7 B7oVw96YpROUm0v8w2D7i1zqtZJOKLt/t+6Bwuf3joppzr51KFiENBIMXTBlB0jq4PsH dQeBQt2bMKO8hkKlAhrA5aDpjmaatJhMWOCMwoXbIB4Ka99HbifDwINp9ML8eX54Zrve VurA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (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 a15si51185581pgd.166.2019.04.17.13.31.23; Wed, 17 Apr 2019 13:31:38 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731852AbfDQUaG (ORCPT + 99 others); Wed, 17 Apr 2019 16:30:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44012 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727147AbfDQUaF (ORCPT ); Wed, 17 Apr 2019 16:30:05 -0400 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 mx1.redhat.com (Postfix) with ESMTPS id 8CD4D3078ADD; Wed, 17 Apr 2019 20:30:05 +0000 (UTC) Received: from gigantic.usersys.redhat.com (helium.bos.redhat.com [10.18.17.132]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D5863608C1; Wed, 17 Apr 2019 20:30:04 +0000 (UTC) From: Bandan Das To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Jiri Olsa Cc: linux-kernel@vger.kernel.org, x86@kernel.org Subject: [PATCH v2] perf/x86: descriptive failure messages for PMU init Date: Wed, 17 Apr 2019 16:30:04 -0400 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 17 Apr 2019 20:30:05 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There's a default warning message that gets printed, however, there are various failure conditions: - a msr read can fail - a msr write can fail - a msr has an unexpected value - all msrs have unexpected values (disable PMU) Lastly, use %llx to silence checkpatch Signed-off-by: Bandan Das --- v2: Remove virt specific pr_debugs Change the default warning message arch/x86/events/core.c | 53 +++++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c index 81911e11a15d..52b0893da78b 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -192,9 +192,16 @@ static void release_pmc_hardware(void) {} static bool check_hw_exists(void) { - u64 val, val_fail = -1, val_new= ~0; - int i, reg, reg_fail = -1, ret = 0; - int bios_fail = 0; + u64 val = -1, val_fail = -1, val_new = ~0; + int i, reg = -1, reg_fail = -1, ret = 0; + + enum { + READ_FAIL = 1, + WRITE_FAIL = 2, + PMU_FAIL = 3, + BIOS_FAIL = 4, + }; + int status = 0; int reg_safe = -1; /* @@ -204,10 +211,13 @@ static bool check_hw_exists(void) for (i = 0; i < x86_pmu.num_counters; i++) { reg = x86_pmu_config_addr(i); ret = rdmsrl_safe(reg, &val); - if (ret) + if (ret) { + status = READ_FAIL; goto msr_fail; + } + if (val & ARCH_PERFMON_EVENTSEL_ENABLE) { - bios_fail = 1; + status = BIOS_FAIL; val_fail = val; reg_fail = reg; } else { @@ -218,11 +228,13 @@ static bool check_hw_exists(void) if (x86_pmu.num_counters_fixed) { reg = MSR_ARCH_PERFMON_FIXED_CTR_CTRL; ret = rdmsrl_safe(reg, &val); - if (ret) + if (ret) { + status = READ_FAIL; goto msr_fail; + } for (i = 0; i < x86_pmu.num_counters_fixed; i++) { if (val & (0x03 << i*4)) { - bios_fail = 1; + status = BIOS_FAIL; val_fail = val; reg_fail = reg; } @@ -236,7 +248,7 @@ static bool check_hw_exists(void) */ if (reg_safe == -1) { - reg = reg_safe; + status = PMU_FAIL; goto msr_fail; } @@ -246,18 +258,22 @@ static bool check_hw_exists(void) * (qemu/kvm) that don't trap on the MSR access and always return 0s. */ reg = x86_pmu_event_addr(reg_safe); - if (rdmsrl_safe(reg, &val)) + if (rdmsrl_safe(reg, &val)) { + status = READ_FAIL; goto msr_fail; + } val ^= 0xffffUL; ret = wrmsrl_safe(reg, val); ret |= rdmsrl_safe(reg, &val_new); - if (ret || val != val_new) + if (ret || val != val_new) { + status = WRITE_FAIL; goto msr_fail; + } /* * We still allow the PMU driver to operate: */ - if (bios_fail) { + if (status == BIOS_FAIL) { pr_cont("Broken BIOS detected, complain to your hardware vendor.\n"); pr_err(FW_BUG "the BIOS has corrupted hw-PMU resources (MSR %x is %Lx)\n", reg_fail, val_fail); @@ -270,8 +286,19 @@ static bool check_hw_exists(void) pr_cont("PMU not available due to virtualization, using software events only.\n"); } else { pr_cont("Broken PMU hardware detected, using software events only.\n"); - pr_err("Failed to access perfctr msr (MSR %x is %Lx)\n", - reg, val_new); + } + switch (status) { + case READ_FAIL: + pr_err("Failed to read perfctr msr (MSR %x)\n", reg); + break; + case WRITE_FAIL: + pr_err("Failed to write perfctr msr (MSR %x, wrote: %llx, read: %llx)\n", + reg, val, val_new); + break; + case PMU_FAIL: + /* fall through for default message */ + default: + pr_err(FW_BUG "the BIOS has corrupted hw-PMU resources.\n"); } return false; -- 2.19.2