Re: [PATCH 1/2] drm/amdgpu/pm: Fix NULL pointer dereference when get power limit

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Mar 13, 2024 at 7:07 AM Ma Jun <Jun.Ma2@xxxxxxx> wrote:
>
> Because powerplay_table initialization is skipped under
> sriov case, We check and set default lower and upper OD
> value if powerplay_table is NULL.
>
> Fixes: 7968e9748fbb ("drm/amdgpu/pm: Fix the power1_min_cap value")
> Signed-off-by: Ma Jun <Jun.Ma2@xxxxxxx>
> Reported-by: Yin Zhenguo <zhenguo.yin@xxxxxxx>
> Suggested-by: Lazar Lijo <lijo.lazar@xxxxxxx>
> Suggested-by: Alex Deucher <Alexander.Deucher@xxxxxxx>

Series is:
Reviewed-by: Alex Deucher <alexander.deucher@xxxxxxx>

> ---
>  .../gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c    | 14 ++++++++------
>  drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c  | 16 +++++++++-------
>  .../drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c  | 14 ++++++++------
>  .../gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c | 14 ++++++++------
>  .../gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c | 14 ++++++++------
>  5 files changed, 41 insertions(+), 31 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c
> index 1d96eb274d72..a406372e79d8 100644
> --- a/drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c
> +++ b/drivers/gpu/drm/amd/pm/swsmu/smu11/arcturus_ppt.c
> @@ -1286,7 +1286,7 @@ static int arcturus_get_power_limit(struct smu_context *smu,
>         struct smu_11_0_powerplay_table *powerplay_table =
>                 (struct smu_11_0_powerplay_table *)smu->smu_table.power_play_table;
>         PPTable_t *pptable = smu->smu_table.driver_pptable;
> -       uint32_t power_limit, od_percent_upper, od_percent_lower;
> +       uint32_t power_limit, od_percent_upper = 0, od_percent_lower = 0;
>
>         if (smu_v11_0_get_current_power_limit(smu, &power_limit)) {
>                 /* the last hope to figure out the ppt limit */
> @@ -1303,12 +1303,14 @@ static int arcturus_get_power_limit(struct smu_context *smu,
>         if (default_power_limit)
>                 *default_power_limit = power_limit;
>
> -       if (smu->od_enabled)
> -               od_percent_upper = le32_to_cpu(powerplay_table->overdrive_table.max[SMU_11_0_ODSETTING_POWERPERCENTAGE]);
> -       else
> -               od_percent_upper = 0;
> +       if (powerplay_table) {
> +               if (smu->od_enabled)
> +                       od_percent_upper = le32_to_cpu(powerplay_table->overdrive_table.max[SMU_11_0_ODSETTING_POWERPERCENTAGE]);
> +               else
> +                       od_percent_upper = 0;
>
> -       od_percent_lower = le32_to_cpu(powerplay_table->overdrive_table.min[SMU_11_0_ODSETTING_POWERPERCENTAGE]);
> +               od_percent_lower = le32_to_cpu(powerplay_table->overdrive_table.min[SMU_11_0_ODSETTING_POWERPERCENTAGE]);
> +       }
>
>         dev_dbg(smu->adev->dev, "od percent upper:%d, od percent lower:%d (default power: %d)\n",
>                                                         od_percent_upper, od_percent_lower, power_limit);
> diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c
> index ed189a3878eb..65bba5fc2335 100644
> --- a/drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c
> +++ b/drivers/gpu/drm/amd/pm/swsmu/smu11/navi10_ppt.c
> @@ -2339,7 +2339,7 @@ static int navi10_get_power_limit(struct smu_context *smu,
>                 (struct smu_11_0_powerplay_table *)smu->smu_table.power_play_table;
>         struct smu_11_0_overdrive_table *od_settings = smu->od_settings;
>         PPTable_t *pptable = smu->smu_table.driver_pptable;
> -       uint32_t power_limit, od_percent_upper, od_percent_lower;
> +       uint32_t power_limit, od_percent_upper = 0, od_percent_lower = 0;
>
>         if (smu_v11_0_get_current_power_limit(smu, &power_limit)) {
>                 /* the last hope to figure out the ppt limit */
> @@ -2356,13 +2356,15 @@ static int navi10_get_power_limit(struct smu_context *smu,
>         if (default_power_limit)
>                 *default_power_limit = power_limit;
>
> -       if (smu->od_enabled &&
> -                   navi10_od_feature_is_supported(od_settings, SMU_11_0_ODCAP_POWER_LIMIT))
> -               od_percent_upper = le32_to_cpu(powerplay_table->overdrive_table.max[SMU_11_0_ODSETTING_POWERPERCENTAGE]);
> -       else
> -               od_percent_upper = 0;
> +       if (powerplay_table) {
> +               if (smu->od_enabled &&
> +                           navi10_od_feature_is_supported(od_settings, SMU_11_0_ODCAP_POWER_LIMIT))
> +                       od_percent_upper = le32_to_cpu(powerplay_table->overdrive_table.max[SMU_11_0_ODSETTING_POWERPERCENTAGE]);
> +               else
> +                       od_percent_upper = 0;
>
> -       od_percent_lower = le32_to_cpu(powerplay_table->overdrive_table.min[SMU_11_0_ODSETTING_POWERPERCENTAGE]);
> +               od_percent_lower = le32_to_cpu(powerplay_table->overdrive_table.min[SMU_11_0_ODSETTING_POWERPERCENTAGE]);
> +       }
>
>         dev_dbg(smu->adev->dev, "od percent upper:%d, od percent lower:%d (default power: %d)\n",
>                                         od_percent_upper, od_percent_lower, power_limit);
> diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c
> index a405424dd699..9371e6e79c56 100644
> --- a/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c
> +++ b/drivers/gpu/drm/amd/pm/swsmu/smu11/sienna_cichlid_ppt.c
> @@ -625,7 +625,7 @@ static int sienna_cichlid_get_power_limit(struct smu_context *smu,
>  {
>         struct smu_11_0_7_powerplay_table *powerplay_table =
>                 (struct smu_11_0_7_powerplay_table *)smu->smu_table.power_play_table;
> -       uint32_t power_limit, od_percent_upper, od_percent_lower;
> +       uint32_t power_limit, od_percent_upper = 0, od_percent_lower = 0;
>         uint16_t *table_member;
>
>         GET_PPTABLE_MEMBER(SocketPowerLimitAc, &table_member);
> @@ -640,12 +640,14 @@ static int sienna_cichlid_get_power_limit(struct smu_context *smu,
>         if (default_power_limit)
>                 *default_power_limit = power_limit;
>
> -       if (smu->od_enabled)
> -               od_percent_upper = le32_to_cpu(powerplay_table->overdrive_table.max[SMU_11_0_7_ODSETTING_POWERPERCENTAGE]);
> -       else
> -               od_percent_upper = 0;
> +       if (powerplay_table) {
> +               if (smu->od_enabled)
> +                       od_percent_upper = le32_to_cpu(powerplay_table->overdrive_table.max[SMU_11_0_7_ODSETTING_POWERPERCENTAGE]);
> +               else
> +                       od_percent_upper = 0;
>
> -       od_percent_lower = le32_to_cpu(powerplay_table->overdrive_table.min[SMU_11_0_7_ODSETTING_POWERPERCENTAGE]);
> +               od_percent_lower = le32_to_cpu(powerplay_table->overdrive_table.min[SMU_11_0_7_ODSETTING_POWERPERCENTAGE]);
> +       }
>
>         dev_dbg(smu->adev->dev, "od percent upper:%d, od percent lower:%d (default power: %d)\n",
>                                         od_percent_upper, od_percent_lower, power_limit);
> diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c
> index 6a501d2661f5..f1e388c2863a 100644
> --- a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c
> +++ b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_0_ppt.c
> @@ -2356,7 +2356,7 @@ static int smu_v13_0_0_get_power_limit(struct smu_context *smu,
>                 (struct smu_13_0_0_powerplay_table *)table_context->power_play_table;
>         PPTable_t *pptable = table_context->driver_pptable;
>         SkuTable_t *skutable = &pptable->SkuTable;
> -       uint32_t power_limit, od_percent_upper, od_percent_lower;
> +       uint32_t power_limit, od_percent_upper = 0, od_percent_lower = 0;
>         uint32_t msg_limit = skutable->MsgLimits.Power[PPT_THROTTLER_PPT0][POWER_SOURCE_AC];
>
>         if (smu_v13_0_get_current_power_limit(smu, &power_limit))
> @@ -2369,12 +2369,14 @@ static int smu_v13_0_0_get_power_limit(struct smu_context *smu,
>         if (default_power_limit)
>                 *default_power_limit = power_limit;
>
> -       if (smu->od_enabled)
> -               od_percent_upper = le32_to_cpu(powerplay_table->overdrive_table.max[SMU_13_0_0_ODSETTING_POWERPERCENTAGE]);
> -       else
> -               od_percent_upper = 0;
> +       if (powerplay_table) {
> +               if (smu->od_enabled)
> +                       od_percent_upper = le32_to_cpu(powerplay_table->overdrive_table.max[SMU_13_0_0_ODSETTING_POWERPERCENTAGE]);
> +               else
> +                       od_percent_upper = 0;
>
> -       od_percent_lower = le32_to_cpu(powerplay_table->overdrive_table.min[SMU_13_0_0_ODSETTING_POWERPERCENTAGE]);
> +               od_percent_lower = le32_to_cpu(powerplay_table->overdrive_table.min[SMU_13_0_0_ODSETTING_POWERPERCENTAGE]);
> +       }
>
>         dev_dbg(smu->adev->dev, "od percent upper:%d, od percent lower:%d (default power: %d)\n",
>                                         od_percent_upper, od_percent_lower, power_limit);
> diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c
> index 3dc7b60cb075..8abf0a772e6b 100644
> --- a/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c
> +++ b/drivers/gpu/drm/amd/pm/swsmu/smu13/smu_v13_0_7_ppt.c
> @@ -2320,7 +2320,7 @@ static int smu_v13_0_7_get_power_limit(struct smu_context *smu,
>                 (struct smu_13_0_7_powerplay_table *)table_context->power_play_table;
>         PPTable_t *pptable = table_context->driver_pptable;
>         SkuTable_t *skutable = &pptable->SkuTable;
> -       uint32_t power_limit, od_percent_upper, od_percent_lower;
> +       uint32_t power_limit, od_percent_upper = 0, od_percent_lower = 0;
>         uint32_t msg_limit = skutable->MsgLimits.Power[PPT_THROTTLER_PPT0][POWER_SOURCE_AC];
>
>         if (smu_v13_0_get_current_power_limit(smu, &power_limit))
> @@ -2333,12 +2333,14 @@ static int smu_v13_0_7_get_power_limit(struct smu_context *smu,
>         if (default_power_limit)
>                 *default_power_limit = power_limit;
>
> -       if (smu->od_enabled)
> -               od_percent_upper = le32_to_cpu(powerplay_table->overdrive_table.max[SMU_13_0_7_ODSETTING_POWERPERCENTAGE]);
> -       else
> -               od_percent_upper = 0;
> +       if (powerplay_table) {
> +               if (smu->od_enabled)
> +                       od_percent_upper = le32_to_cpu(powerplay_table->overdrive_table.max[SMU_13_0_7_ODSETTING_POWERPERCENTAGE]);
> +               else
> +                       od_percent_upper = 0;
>
> -       od_percent_lower = le32_to_cpu(powerplay_table->overdrive_table.min[SMU_13_0_7_ODSETTING_POWERPERCENTAGE]);
> +               od_percent_lower = le32_to_cpu(powerplay_table->overdrive_table.min[SMU_13_0_7_ODSETTING_POWERPERCENTAGE]);
> +       }
>
>         dev_dbg(smu->adev->dev, "od percent upper:%d, od percent lower:%d (default power: %d)\n",
>                                         od_percent_upper, od_percent_lower, power_limit);
> --
> 2.34.1
>




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux