Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp179041imd; Wed, 31 Oct 2018 16:55:07 -0700 (PDT) X-Google-Smtp-Source: AJdET5e5HXwmi6rqtTNM2zT1mM06Hvl17Jn8MHS1F828iAXGY8E5+rp1orztfCh7qE94bXv0j3m1 X-Received: by 2002:a63:6848:: with SMTP id d69-v6mr5129534pgc.113.1541030107705; Wed, 31 Oct 2018 16:55:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541030107; cv=none; d=google.com; s=arc-20160816; b=x21dS9exx7BVcFQia2NuwoQyeIXdo4ziDBvwDUF/2NU9HFsZftYuoTA6CVHCMAWOTq xjDlzAKSCrKDi8Zn0uTOAj4/Eza7V7JLntiSCcyn30taJo/uA5BRijD226+JU18rBLAa PSSx2Tb9Xls9ZvpQcih/Xjb6ku3O6kqNOZhQiy2dGxxvcArOSjq7iVb2pTY8WUdlfrOD EgHuxTS1LraasAl8WCHaFOuIlJMgiejmNw7h/kIupps1oniBf01SLGEyYvbGU4wQvqoU AilHGjQ0JZG/1yYqzh+U7vvMF0kIp8pDKCkClcF2In86Oisnszbzmi8Vosp3e6sqpoX4 F1Tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=q2udVQrYf4Ocya2M7mZ9xtk3DgVbZmg6hJZ7fzEodeE=; b=EQQKLVhegzYkIosNba5jRnz5MtZ+dnZvEA6REs+7GgUotZQokPXK7eQQ2DTXuSYCrE jtBLWlbrGPzdXtQ+etu2kLss5QAlvHpza0pdLd1dNO2QTIkdkn5xXpz7VhGCasrIbfua 8Bk5Q4jdEN6gcSybYIV7c/Z0vtzsJl/0ATvk8TbgY9YT12TEC4NW6Zz9tnPg9L9cOYHp MvgJRtDd4D8C0X0BSCf63/r9MtHvbNLwKZlaqVDC9CVa6+QvKGwRMPi+/9ZH8DzFxmWG ZnHLGRr8tgErPSPL2SqMEKuhwULqrKj61wzsK7qubm7FGX8OM40d3IQALfivainejMLE f5iw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=X4qYsPHh; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v64-v6si34776780pfj.167.2018.10.31.16.54.53; Wed, 31 Oct 2018 16:55:07 -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; dkim=pass header.i=@kernel.org header.s=default header.b=X4qYsPHh; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728020AbeKAIxo (ORCPT + 99 others); Thu, 1 Nov 2018 04:53:44 -0400 Received: from mail.kernel.org ([198.145.29.99]:52984 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727679AbeKAIGN (ORCPT ); Thu, 1 Nov 2018 04:06:13 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 64E2720823; Wed, 31 Oct 2018 23:06:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541027163; bh=/VR6lIXXafUpjR7JKWNbP5Sg9DM1QgMytnddXxMsHMU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X4qYsPHhPeAsvNtakMEgpvjgnh86yxb1fAs+WjkqALUtuPtnQVGFqz+aMb6fA4Eiy TkReq18VtpTksSoPCfUv3t0yDLf46uWa+BRhDYEyT/67aVgLTStK1TBikENNLIqQOJ 2gsvpNpNBD+LGk4YV99XVQGWnUroKLPboPhEjZ4k= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Prarit Bhargava , Shuah Khan , Stafford Horne , Sasha Levin Subject: [PATCH AUTOSEL 4.19 022/146] cpupower: Fix coredump on VMWare Date: Wed, 31 Oct 2018 19:03:37 -0400 Message-Id: <20181031230541.28822-22-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031230541.28822-1-sashal@kernel.org> References: <20181031230541.28822-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Prarit Bhargava [ Upstream commit f69ffc5d3db8f1f03fd6d1df5930f9a1fbd787b6 ] cpupower crashes on VMWare guests. The guests have the AMD PStateDef MSR (0xC0010064 + state number) set to zero. As a result fid and did are zero and the crash occurs because of a divide by zero (cof = fid/did). This can be prevented by checking the enable bit in the PStateDef MSR before calculating cof. By doing this the value of pstate[i] remains zero and the value can be tested before displaying the active Pstates. Check the enable bit in the PstateDef register for all supported families and only print out enabled Pstates. Signed-off-by: Prarit Bhargava Cc: Shuah Khan Cc: Stafford Horne Signed-off-by: Shuah Khan (Samsung OSG) Signed-off-by: Sasha Levin --- tools/power/cpupower/utils/cpufreq-info.c | 2 ++ tools/power/cpupower/utils/helpers/amd.c | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/tools/power/cpupower/utils/cpufreq-info.c b/tools/power/cpupower/utils/cpufreq-info.c index df43cd45d810..ccd08dd00996 100644 --- a/tools/power/cpupower/utils/cpufreq-info.c +++ b/tools/power/cpupower/utils/cpufreq-info.c @@ -200,6 +200,8 @@ static int get_boost_mode(unsigned int cpu) printf(_(" Boost States: %d\n"), b_states); printf(_(" Total States: %d\n"), pstate_no); for (i = 0; i < pstate_no; i++) { + if (!pstates[i]) + continue; if (i < b_states) printf(_(" Pstate-Pb%d: %luMHz (boost state)" "\n"), i, pstates[i]); diff --git a/tools/power/cpupower/utils/helpers/amd.c b/tools/power/cpupower/utils/helpers/amd.c index bb41cdd0df6b..58d23997424d 100644 --- a/tools/power/cpupower/utils/helpers/amd.c +++ b/tools/power/cpupower/utils/helpers/amd.c @@ -119,6 +119,11 @@ int decode_pstates(unsigned int cpu, unsigned int cpu_family, } if (read_msr(cpu, MSR_AMD_PSTATE + i, &pstate.val)) return -1; + if ((cpu_family == 0x17) && (!pstate.fam17h_bits.en)) + continue; + else if (!pstate.bits.en) + continue; + pstates[i] = get_cof(cpu_family, pstate); } *no = i; -- 2.17.1