Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

amdgpu/pm: Fix possible array out-of-bounds if SCLK levels != 2

[v2]
simplified fix after Lijo's feedback
removed clocks.num_levels from calculation of loop count
removed unsafe accesses to shim table freq_values
retained corner case output only min,now if
clocks.num_levels == 1 && now > min

[v1]
added a check to populate and use SCLK shim table freq_values only
if using dpm_level == AMD_DPM_FORCED_LEVEL_MANUAL or
AMD_DPM_FORCED_LEVEL_PERF_DETERMINISM
removed clocks.num_levels from calculation of shim table size
removed unsafe accesses to shim table freq_values
output gfx_table values if using other dpm levels
added check for freq_match when using freq_values for when now == min_clk

== Test ==
LOGFILE=aldebaran-sclk.test.log
AMDGPU_PCI_ADDR=`lspci -nn | grep "VGA\|Display" | cut -d " " -f 1`
AMDGPU_HWMON=`ls -la /sys/class/hwmon | grep $AMDGPU_PCI_ADDR | awk '{print $9}'`
HWMON_DIR=/sys/class/hwmon/${AMDGPU_HWMON}

lspci -nn | grep "VGA\|Display" > $LOGFILE
FILES="pp_od_clk_voltage
pp_dpm_sclk"

for f in $FILES
do
echo === $f === >> $LOGFILE
cat $HWMON_DIR/device/$f >> $LOGFILE
done
cat $LOGFILE

Signed-off-by: Darren Powell <darren.powell@amd.com>
Reviewed-by: Kenneth Feng <kenneth.feng@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Darren Powell and committed by
Alex Deucher
ceb18036 543faf57

+12 -22
+12 -22
drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c
··· 746 746 struct smu_13_0_dpm_table *single_dpm_table; 747 747 struct smu_dpm_context *smu_dpm = &smu->smu_dpm; 748 748 struct smu_13_0_dpm_context *dpm_context = NULL; 749 - uint32_t display_levels; 749 + int display_levels; 750 750 uint32_t freq_values[3] = {0}; 751 751 uint32_t min_clk, max_clk; 752 752 ··· 778 778 return ret; 779 779 } 780 780 781 - display_levels = clocks.num_levels; 781 + display_levels = (clocks.num_levels == 1) ? 1 : 2; 782 782 783 783 min_clk = pstate_table->gfxclk_pstate.curr.min; 784 784 max_clk = pstate_table->gfxclk_pstate.curr.max; ··· 788 788 789 789 /* fine-grained dpm has only 2 levels */ 790 790 if (now > min_clk && now < max_clk) { 791 - display_levels = clocks.num_levels + 1; 791 + display_levels++; 792 792 freq_values[2] = max_clk; 793 793 freq_values[1] = now; 794 794 } 795 795 796 - /* 797 - * For DPM disabled case, there will be only one clock level. 798 - * And it's safe to assume that is always the current clock. 799 - */ 800 - if (display_levels == clocks.num_levels) { 801 - for (i = 0; i < clocks.num_levels; i++) 802 - size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n", i, 803 - freq_values[i], 804 - (clocks.num_levels == 1) ? 805 - "*" : 806 - (aldebaran_freqs_in_same_level( 807 - freq_values[i], now) ? 808 - "*" : 809 - "")); 810 - } else { 811 - for (i = 0; i < display_levels; i++) 812 - size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n", i, 813 - freq_values[i], i == 1 ? "*" : ""); 814 - } 796 + for (i = 0; i < display_levels; i++) 797 + size += sysfs_emit_at(buf, size, "%d: %uMhz %s\n", i, 798 + freq_values[i], 799 + (display_levels == 1) ? 800 + "*" : 801 + (aldebaran_freqs_in_same_level( 802 + freq_values[i], now) ? 803 + "*" : 804 + "")); 815 805 816 806 break; 817 807