From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ABBAA606A339 for ; Sun, 6 Dec 2026 05:15:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=i4VUca2o Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4C44610E2D5; Sun, 6 Dec 2026 05:15:33 +0000 (UTC) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4180310E2D5; Sun, 6 Dec 2026 05:15:27 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 2075144FDD; Sun, 6 Dec 2026 05:15:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7BC01F00A1D; Sun, 6 Dec 2026 05:15:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796534127; bh=05SMFChyjhVHkN9kG7UcVM64ILyoPeFVeBrw3ZkncL0=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=i4VUca2oNzexDM4iNU6XdtKkLM7z8iSiJbeSnm2uTy3RoRgC3WZfU9SRjDV6KH887 e/aUrvHnMGLsv2N6s88MgO2LAgrZmmxftuwohtkbFoTQUx7wAUA3659oteB1+VkpNm KpV9XW5od5LZwY7+gej7Iv88/1mTMz04W69pw1pCU51AFTL7hglwSgy26ybVrAOPw+ TPfcHNM1sqn28QNt8ochYmO2Ofo5ghOmZP8gH+65xYZ/e2T0reGDdBcvtHt7DmE/8l 7eeNxpCVkwlOwQCWDzDM3rfxs2VbnJqwj6vhdOGJRC6v5CHNU5COHDxXMc8Bvhibop +BLddxnpMvzFQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v3 3/4] drm/amd/pm: allow editing the smu8 overdrive sclk table To: "Joshua Horne" Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org In-Reply-To: <20261205-smu8-overdrive-v3-3-46890aa116e7@etsu.edu> References: <20261205-smu8-overdrive-v3-0-46890aa116e7@etsu.edu> <20261205-smu8-overdrive-v3-3-46890aa116e7@etsu.edu> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Sun, 06 Dec 2026 05:15:26 +0000 X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "amd-gfx" X-Spam-Status: No, score=-11.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Medium] drm/amd/pm: smu8_get_sclk_level() returns invalid index after OD SCLK edits - [Medium] drm/amd/pm: TOCTOU race between smu8 OD commit validation and table upload - [Low] drm/amd/pm: smu8_od_commit_sclk_table() validates hidden disabled levels -- commit d6d2988f15e1e2d033c702075f930806b90d4b90 Author: Joshua Horne drm/amd/pm: allow editing the smu8 overdrive sclk table This commit implements the "s", "r", and "c" pp_od_clk_voltage commands for Carrizo and Stoney by adding smu8_odn_edit_dpm_table() and uploading the edited SCLK table during power state readjustment. > diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu8_hwmgr.c b/driver= s/gpu/drm/amd/pm/powerplay/hwmgr/smu8_hwmgr.c > index 0bfb9ef721512..17c720d04728d 100644 > --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu8_hwmgr.c > +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu8_hwmgr.c > @@ -858,10 +858,92 @@ static void smu8_populate_umdpstate_clocks(struct p= p_hwmgr *hwmgr) [ ... ] > +static int smu8_od_upload_sclk_table(struct pp_hwmgr *hwmgr) [ ... ] > + /* the NB voltages (GnbVid) of the levels are left untouched */ > + for (i =3D 0; i < od->num_of_pl; i++) { > + vddc_table->entries[i].clk =3D od->entries[i].clock; > + vdd_gfx_table->entries[i].clk =3D od->entries[i].clock; > + vdd_gfx_table->entries[i].v =3D > + convert_to_vid(od->entries[i].vddc); > + } > + > + smu8_populate_umdpstate_clocks(hwmgr); > + > + /* > + * The SMU gets the display minimum as a level index, which may differ > + * in the new table: make smu8_update_sclk_limit() send it again. > + */ > + data->sclk_dpm.hard_min_clk =3D 0; [Severity: Medium] Can overwriting vddc_dependency_on_sclk cause smu8_get_sclk_level() to retu= rn an out-of-bounds or disabled level index to the SMU? Neither search loop in smu8_get_sclk_level() clamps its return value to the enabled levels: drivers/gpu/drm/amd/pm/powerplay/hwmgr/smu8_hwmgr.c:smu8_get_sclk_level() { ... case PPSMC_MSG_SetSclkSoftMin: case PPSMC_MSG_SetSclkHardMin: for (i =3D 0; i < (int)table->count; i++) { if (clock <=3D table->entries[i].clk) break; } break; case PPSMC_MSG_SetSclkSoftMax: case PPSMC_MSG_SetSclkHardMax: for (i =3D table->count - 1; i >=3D 0; i--) { if (clock >=3D table->entries[i].clk) break; } break; ... } If all enabled levels are underclocked below display_config->min_core_set_c= lock, smu8_update_sclk_limit() sends table->count (past the end of the table) or a fused-off level >=3D smu8_get_max_sclk_level() to PPSMC_MSG_SetSclkHardMin. Similarly, on resume smu8_program_bootup_state() looks up the unchanged VBI= OS bootup_engine_clock; if level 0 was raised above it, the descending loop ex= its at -1 and sends 0xFFFFFFFF to PPSMC_MSG_SetSclkSoftMax, which stays active = in manual force-performance-level mode. Clamping smu8_get_sclk_level() to [0, min(table->count, smu8_get_max_sclk_level(hwmgr)) - 1] would prevent th= is. [ ... ] > @@ -2065,6 +2147,149 @@ static void smu8_dpm_powergate_vce(struct pp_hwmg= r *hwmgr, bool bgate) [ ... ] > +static int smu8_od_commit_sclk_table(struct pp_hwmgr *hwmgr) > +{ > + struct smu8_hwmgr *data =3D hwmgr->backend; > + struct phm_odn_clock_levels *od =3D &data->od_edit_sclk; > + struct phm_clock_voltage_dependency_table *table =3D > + hwmgr->dyn_state.vddc_dependency_on_sclk; > + struct amdgpu_device *adev =3D hwmgr->adev; > + uint32_t i, clk, prev =3D 0; > + > + /* the levels that the SMU does not enable keep their clocks */ > + for (i =3D 0; i < table->count; i++) { > + clk =3D i < od->num_of_pl ? od->entries[i].clock : > + table->entries[i].clk; > + if (clk <=3D prev) { > + dev_info(adev->dev, "OD sclk levels must increase\n"); > + return -EINVAL; > + } > + prev =3D clk; > + } [Severity: Low] Will this loop reject clocks that OD_RANGE advertises and smu8_od_edit_sclk_level() accepts on fused SKUs where od->num_of_pl < table->count? init_overdrive_limits_V2_1() populates overdriveLimit.engineClock directly from the VBIOS without clamping it below table->entries[od->num_of_pl].clk, while OD_SCLK hides levels at or above od->num_of_pl and smu8_od_edit_sclk_level() forbids editing them. If overdriveLimit.engineCl= ock is at or above the first hidden level, committing an accepted clock fails w= ith -EINVAL against a level the user cannot see or edit. Also, if the VBIOS contains duplicate or non-increasing clocks in the disab= led trailing entries, every commit (including voltage-only edits or "r" followed by "c") will fail with -EINVAL. > + > + /* uploaded by the power state readjustment that follows a commit */ > + data->od_update_pending =3D true; > + > + return 0; > +} > + > +static int smu8_odn_edit_dpm_table(struct pp_hwmgr *hwmgr, > + enum PP_OD_DPM_TABLE_COMMAND type, > + long *input, uint32_t size) [ ... ] > + switch (type) { > + case PP_OD_EDIT_SCLK_VDDC_TABLE: > + break; > + case PP_OD_RESTORE_DEFAULT_TABLE: > + data->od_edit_sclk =3D data->od_default_sclk; > + return 0; > + case PP_OD_COMMIT_DPM_TABLE: > + return smu8_od_commit_sclk_table(hwmgr); > + default: > + return -EINVAL; > + } [ ... ] > + data->od_edit_sclk =3D od; [Severity: Medium] Can a concurrent write to pp_od_clk_voltage overwrite data->od_edit_sclk between commit validation and upload? amdgpu_set_pp_od_clk_voltage() releases adev->pm.mutex between amdgpu_dpm_odn_edit_dpm_table() and amdgpu_dpm_dispatch_task(), and neither PP_OD_EDIT_SCLK_VDDC_TABLE nor PP_OD_RESTORE_DEFAULT_TABLE clears data->od_update_pending: CPU0 CPU1 amdgpu_set_pp_od_clk_voltage("c") amdgpu_dpm_odn_edit_dpm_table() lock(&adev->pm.mutex) smu8_od_commit_sclk_table() data->od_update_pending =3D true unlock(&adev->pm.mutex) amdgpu_set_pp_od_clk_voltage("s ...= ") amdgpu_dpm_odn_edit_dpm_table() lock(&adev->pm.mutex) data->od_edit_sclk =3D od unlock(&adev->pm.mutex) amdgpu_dpm_dispatch_task(...) lock(&adev->pm.mutex) smu8_od_upload_sclk_table() <-- uploads unvalidated table unlock(&adev->pm.mutex) Because smu8_od_upload_sclk_table() reads directly from data->od_edit_sclk without re-checking monotonicity, a non-monotonic or duplicate-clock table can be written to the dependency tables, power states, and SMU, breaking smu8_get_sclk_level() and clock-equality matching in smu8_od_update_power_state(). Snapshotting the validated table on commit (or clearing od_update_pending on edit and restore) would close this window. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261205-smu8-overd= rive-v3-0-46890aa116e7@etsu.edu?part=3D3