Re: [PATCH 3.18 16/90] cpupower: Fix coredump on VMWare

From: Prarit Bhargava
Date: Mon Nov 19 2018 - 13:11:58 EST




On 11/19/2018 11:28 AM, Greg Kroah-Hartman wrote:
> 3.18-stable review patch. If anyone has any objections, please let me know.
>
> ------------------
>
> From: Prarit Bhargava <prarit@xxxxxxxxxx>
>
> [ Upstream commit f69ffc5d3db8f1f03fd6d1df5930f9a1fbd787b6 ]

Greg, as previously mentioned to Sasha, this patch also needs 8c22e2f69592
("cpupower: Fix AMD Family 0x17 msr_pstate size"). I did not see a message
indicating that 8c22e2f69592 was also being backported to 3.18-stable. My
apologies if I missed it.

P.


>
> 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 <prarit@xxxxxxxxxx>
> Cc: Shuah Khan <shuah@xxxxxxxxxx>
> Cc: Stafford Horne <shorne@xxxxxxxxx>
> Signed-off-by: Shuah Khan (Samsung OSG) <shuah@xxxxxxxxxx>
> Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>
> Signed-off-by: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
> ---
> tools/power/cpupower/utils/cpufreq-info.c | 2 ++
> tools/power/cpupower/utils/helpers/amd.c | 5 +++++
> 2 files changed, 7 insertions(+)
>
> --- 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 c
> 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]);
> --- a/tools/power/cpupower/utils/helpers/amd.c
> +++ b/tools/power/cpupower/utils/helpers/amd.c
> @@ -103,6 +103,11 @@ int decode_pstates(unsigned int cpu, uns
> }
> 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;
>
>