From: "Lazar, Lijo" <lijo.lazar@amd.com>
To: Jiang Liu <gerry@linux.alibaba.com>,
alexander.deucher@amd.com, christian.koenig@amd.com,
Xinhui.Pan@amd.com, airlied@gmail.com, simona@ffwll.ch,
sunil.khatri@amd.com, Hawking.Zhang@amd.com,
mario.limonciello@amd.com, xiaogang.chen@amd.com,
Kent.Russell@amd.com, shuox.liu@linux.alibaba.com,
amd-gfx@lists.freedesktop.org, Tao Zhou <Tao.Zhou1@amd.com>
Subject: Re: [RFC v2 06/15] drm/amdgpu: enhance amdgpu_ras_pre_fini() to better support SR
Date: Fri, 17 Jan 2025 11:39:50 +0530 [thread overview]
Message-ID: <633e6872-7a5b-415e-a617-ecd2e59e83ae@amd.com> (raw)
In-Reply-To: <d07f0c4ed71a8f4b3e6194881f7cc00826240951.1736732062.git.gerry@linux.alibaba.com>
On 1/13/2025 7:12 AM, Jiang Liu wrote:
> Enhance amdgpu_ras_pre_fini() to better support suspend/resume by:
> 1) fix possible resource leakage. amdgpu_release_ras_context() only
> kfree(con) but doesn't release resources associated with the con
> object.
> 2) call amdgpu_ras_pre_fini() in amdgpu_device_suspend() to undo what
> has been done by amdgpu_ras_late_init(), because amdgpu_device_resume()
> will invoke amdgpu_ras_late_init() on resume.
> 3) move amdgpu_ras_recovery_fini() from amdgpu_ras_pre_fini() to
> amdgpu_ras_fini()
> 4) move calling of `obj->ras_fini()` from amdgpu_ras_fini() to
> amdgpu_ras_pre_fini().
>
> Signed-off-by: Jiang Liu <gerry@linux.alibaba.com>
> ---
> drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 6 ++-
> drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c | 44 +++++++++++++---------
> 2 files changed, 31 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> index 0a121aab5c74..2bfe113e17c7 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> @@ -4613,6 +4613,8 @@ int amdgpu_device_init(struct amdgpu_device *adev,
> return 0;
>
> release_ras_con:
> + amdgpu_ras_pre_fini(adev);
> + amdgpu_ras_fini(adev);
> if (amdgpu_sriov_vf(adev))
> amdgpu_virt_release_full_gpu(adev, true);
>
> @@ -4627,8 +4629,6 @@ int amdgpu_device_init(struct amdgpu_device *adev,
> adev->virt.ops = NULL;
> r = -EAGAIN;
> }
> - amdgpu_release_ras_context(adev);
> -
> failed:
> amdgpu_vf_error_trans_all(adev);
>
> @@ -4921,6 +4921,8 @@ int amdgpu_device_suspend(struct drm_device *dev, bool notify_clients)
>
> cancel_delayed_work_sync(&adev->delayed_init_work);
>
> + /* disable ras feature must before hw fini */
> + amdgpu_ras_pre_fini(adev);
> amdgpu_ras_suspend(adev);
Based on the usages above, it makes more sense to keep
amdgpu_ras_pre_fini as a static function and call in
ras_fini/ras_suspend (contain the calls at ras layer and avoid another
new public interface).
Copying Tao to take a look.
Thanks,
Lijo
>
> amdgpu_device_ip_suspend_phase1(adev);
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
> index 7bbab7297c97..5ac63f9cffda 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ras.c
> @@ -4270,42 +4270,49 @@ int amdgpu_ras_late_init(struct amdgpu_device *adev)
> int amdgpu_ras_pre_fini(struct amdgpu_device *adev)
> {
> struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
> + struct amdgpu_ras_block_list *node, *tmp;
> + struct amdgpu_ras_block_object *obj;
>
> - if (!adev->ras_enabled || !con)
> - return 0;
> + if (amdgpu_sriov_vf(adev) && !amdgpu_sriov_ras_telemetry_en(adev))
> + goto disable;
>
> + list_for_each_entry_safe(node, tmp, &adev->ras_list, node) {
> + obj = node->ras_obj;
> + if (!obj)
> + continue;
> +
> + if (!amdgpu_ras_is_supported(adev, obj->ras_comm.block))
> + continue;
> +
> + if (obj->ras_fini)
> + obj->ras_fini(adev, &obj->ras_comm);
> + else
> + amdgpu_ras_block_late_fini_default(adev, &obj->ras_comm);
> + }
>
> +disable:
> /* Need disable ras on all IPs here before ip [hw/sw]fini */
> - if (AMDGPU_RAS_GET_FEATURES(con->features))
> + if (con && AMDGPU_RAS_GET_FEATURES(con->features))
> amdgpu_ras_disable_all_features(adev, 0);
> - amdgpu_ras_recovery_fini(adev);
> +
> return 0;
> }
>
> int amdgpu_ras_fini(struct amdgpu_device *adev)
> {
> struct amdgpu_ras_block_list *ras_node, *tmp;
> - struct amdgpu_ras_block_object *obj = NULL;
> struct amdgpu_ras *con = amdgpu_ras_get_context(adev);
>
> if (!adev->ras_enabled || !con)
> - return 0;
> + goto out_free_context;
>
> list_for_each_entry_safe(ras_node, tmp, &adev->ras_list, node) {
> - if (ras_node->ras_obj) {
> - obj = ras_node->ras_obj;
> - if (amdgpu_ras_is_supported(adev, obj->ras_comm.block) &&
> - obj->ras_fini)
> - obj->ras_fini(adev, &obj->ras_comm);
> - else
> - amdgpu_ras_block_late_fini_default(adev, &obj->ras_comm);
> - }
> -
> /* Clear ras blocks from ras_list and free ras block list node */
> list_del(&ras_node->node);
> kfree(ras_node);
> }
>
> + amdgpu_ras_recovery_fini(adev);
> amdgpu_ras_fs_fini(adev);
> amdgpu_ras_interrupt_remove_all(adev);
>
> @@ -4323,8 +4330,11 @@ int amdgpu_ras_fini(struct amdgpu_device *adev)
>
> cancel_delayed_work_sync(&con->ras_counte_delay_work);
>
> - amdgpu_ras_set_context(adev, NULL);
> - kfree(con);
> +out_free_context:
> + if (con) {
> + amdgpu_ras_set_context(adev, NULL);
> + kfree(con);
> + }
>
> return 0;
> }
next prev parent reply other threads:[~2025-01-17 6:10 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-13 1:42 [RFC v2 00/15] Enhance device state machine to better support suspend/resume Jiang Liu
2025-01-13 1:42 ` [RFC v2 01/15] drm/amdgpu: add helper functions to track status for ras manager Jiang Liu
2025-01-17 1:13 ` Wang, Yang(Kevin)
2025-01-17 5:03 ` Lazar, Lijo
2025-01-13 1:42 ` [RFC v2 02/15] drm/amdgpu: add a flag to track ras debugfs creation status Jiang Liu
2025-01-17 5:24 ` Lazar, Lijo
2025-01-13 1:42 ` [RFC v2 03/15] drm/amdgpu: free all resources on error recovery path of amdgpu_ras_init() Jiang Liu
2025-01-16 21:02 ` Mario Limonciello
2025-01-17 5:39 ` Lazar, Lijo
2025-01-13 1:42 ` [RFC v2 04/15] drm/amdgpu: introduce a flag to track refcount held for features Jiang Liu
2025-01-17 5:46 ` Lazar, Lijo
2025-01-13 1:42 ` [RFC v2 05/15] drm/amdgpu: enhance amdgpu_ras_block_late_fini() Jiang Liu
2025-01-16 21:10 ` Mario Limonciello
2025-01-17 5:54 ` Lazar, Lijo
2025-01-13 1:42 ` [RFC v2 06/15] drm/amdgpu: enhance amdgpu_ras_pre_fini() to better support SR Jiang Liu
2025-01-16 21:19 ` Mario Limonciello
2025-01-17 6:09 ` Lazar, Lijo [this message]
2025-01-13 1:42 ` [RFC v2 07/15] drm/admgpu: rename amdgpu_ras_pre_fini() to amdgpu_ras_early_fini() Jiang Liu
2025-01-16 21:25 ` Mario Limonciello
2025-01-17 1:19 ` Wang, Yang(Kevin)
2025-01-17 8:37 ` Lazar, Lijo
2025-01-13 1:42 ` [RFC v2 08/15] drm/amdgpu: make IP block state machine works in stack like way Jiang Liu
2025-01-17 8:45 ` Lazar, Lijo
2025-01-13 1:42 ` [RFC v2 09/15] drm/amdgpu_dm: enhance amdgpu_dm_early_fini() for PM ops Jiang Liu
2025-01-16 21:30 ` Mario Limonciello
2025-01-13 1:42 ` [RFC v2 10/15] drm/admgpu: make device state machine work in stack like way Jiang Liu
2025-01-13 22:27 ` Mario Limonciello
2025-01-14 1:58 ` Gerry Liu
2025-01-15 19:36 ` Mario Limonciello
2025-01-17 8:54 ` Lazar, Lijo
2025-01-13 1:42 ` [RFC v2 11/15] drm/amdgpu: convert ip block bool flags into an enum Jiang Liu
2025-01-17 8:57 ` Lazar, Lijo
2025-01-13 1:42 ` [RFC v2 12/15] drm/amdgpu: introduce IP block iterators to reduce duplicated code Jiang Liu
2025-01-13 1:42 ` [RFC v2 13/15] drm/amdgpu: walk IP blocks in reverse order when shutdown Jiang Liu
2025-01-13 22:28 ` Mario Limonciello
2025-01-13 1:42 ` [RFC v2 14/15] drm/amdgpu/nbio: improve the way to manage irq reference count Jiang Liu
2025-01-13 1:42 ` [RFC v2 15/15] drm/amdgpu/asic: make ip block operations symmetric by .early_fini() Jiang Liu
2025-01-20 6:27 ` [RFC v2 00/15] Enhance device state machine to better support suspend/resume Zhang, Hawking
2025-01-23 0:02 ` Mika Laitio
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=633e6872-7a5b-415e-a617-ecd2e59e83ae@amd.com \
--to=lijo.lazar@amd.com \
--cc=Hawking.Zhang@amd.com \
--cc=Kent.Russell@amd.com \
--cc=Tao.Zhou1@amd.com \
--cc=Xinhui.Pan@amd.com \
--cc=airlied@gmail.com \
--cc=alexander.deucher@amd.com \
--cc=amd-gfx@lists.freedesktop.org \
--cc=christian.koenig@amd.com \
--cc=gerry@linux.alibaba.com \
--cc=mario.limonciello@amd.com \
--cc=shuox.liu@linux.alibaba.com \
--cc=simona@ffwll.ch \
--cc=sunil.khatri@amd.com \
--cc=xiaogang.chen@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox