From nobody Mon Sep 29 21:07:52 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1F65C00140 for ; Mon, 15 Aug 2022 23:59:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351698AbiHOX7x (ORCPT ); Mon, 15 Aug 2022 19:59:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1355714AbiHOXww (ORCPT ); Mon, 15 Aug 2022 19:52:52 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BF691593C8; Mon, 15 Aug 2022 13:17:24 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 80B36B80EA8; Mon, 15 Aug 2022 20:17:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C90CAC433D6; Mon, 15 Aug 2022 20:17:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660594641; bh=ylbPaYMzLJbX63q056f+tawwLu3RIWN+UcwyojSykhQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UlKVdNoNzZQqotDBtCLQningQAboYvKjAm4c43IF9hnj4TzALsoFmlsFD/qSAtodd mBvELBb1jZp/vreE9s35CLMAylpuFKu/xkLeTGIQF7KbvZAzSN53I4BBrbazi9Djko H4bCGlvCO8zur8mAhTa7mSLZAqw5bTtWDtnxkMfc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Evan Quan , Alex Deucher , Sasha Levin Subject: [PATCH 5.19 0511/1157] drm/amdgpu: restore original stable pstate on ctx fini Date: Mon, 15 Aug 2022 19:57:47 +0200 Message-Id: <20220815180500.128135984@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180439.416659447@linuxfoundation.org> References: <20220815180439.416659447@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Alex Deucher [ Upstream commit 958afce98c2c86732483458c03540d3c6ef45254 ] Save the original stable pstate on ctx init and restore it on ctx fini so that we restore a manually selected stable pstate on ctx exit. v2: fix init order (Alex) v3: don't add new variable to ctx struct (Evan) Fixes: c65b364c52ba ("drm/amdgpu/ctx: only reset stable pstate if the user = changed it (v2)") Reviewed-by: Evan Quan Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c | 60 ++++++++++++++----------- 1 file changed, 33 insertions(+), 27 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c b/drivers/gpu/drm/amd/= amdgpu/amdgpu_ctx.c index 7dc92ef36b2b..8534c4c3b337 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c @@ -271,32 +271,6 @@ static ktime_t amdgpu_ctx_fini_entity(struct amdgpu_ct= x_entity *entity) return res; } =20 -static int amdgpu_ctx_init(struct amdgpu_ctx_mgr *mgr, int32_t priority, - struct drm_file *filp, struct amdgpu_ctx *ctx) -{ - int r; - - r =3D amdgpu_ctx_priority_permit(filp, priority); - if (r) - return r; - - memset(ctx, 0, sizeof(*ctx)); - - kref_init(&ctx->refcount); - ctx->mgr =3D mgr; - spin_lock_init(&ctx->ring_lock); - mutex_init(&ctx->lock); - - ctx->reset_counter =3D atomic_read(&mgr->adev->gpu_reset_counter); - ctx->reset_counter_query =3D ctx->reset_counter; - ctx->vram_lost_counter =3D atomic_read(&mgr->adev->vram_lost_counter); - ctx->init_priority =3D priority; - ctx->override_priority =3D AMDGPU_CTX_PRIORITY_UNSET; - ctx->stable_pstate =3D AMDGPU_CTX_STABLE_PSTATE_NONE; - - return 0; -} - static int amdgpu_ctx_get_stable_pstate(struct amdgpu_ctx *ctx, u32 *stable_pstate) { @@ -325,6 +299,38 @@ static int amdgpu_ctx_get_stable_pstate(struct amdgpu_= ctx *ctx, return 0; } =20 +static int amdgpu_ctx_init(struct amdgpu_ctx_mgr *mgr, int32_t priority, + struct drm_file *filp, struct amdgpu_ctx *ctx) +{ + u32 current_stable_pstate; + int r; + + r =3D amdgpu_ctx_priority_permit(filp, priority); + if (r) + return r; + + memset(ctx, 0, sizeof(*ctx)); + + kref_init(&ctx->refcount); + ctx->mgr =3D mgr; + spin_lock_init(&ctx->ring_lock); + mutex_init(&ctx->lock); + + ctx->reset_counter =3D atomic_read(&mgr->adev->gpu_reset_counter); + ctx->reset_counter_query =3D ctx->reset_counter; + ctx->vram_lost_counter =3D atomic_read(&mgr->adev->vram_lost_counter); + ctx->init_priority =3D priority; + ctx->override_priority =3D AMDGPU_CTX_PRIORITY_UNSET; + + r =3D amdgpu_ctx_get_stable_pstate(ctx, ¤t_stable_pstate); + if (r) + return r; + + ctx->stable_pstate =3D current_stable_pstate; + + return 0; +} + static int amdgpu_ctx_set_stable_pstate(struct amdgpu_ctx *ctx, u32 stable_pstate) { @@ -396,7 +402,7 @@ static void amdgpu_ctx_fini(struct kref *ref) } =20 if (drm_dev_enter(&adev->ddev, &idx)) { - amdgpu_ctx_set_stable_pstate(ctx, AMDGPU_CTX_STABLE_PSTATE_NONE); + amdgpu_ctx_set_stable_pstate(ctx, ctx->stable_pstate); drm_dev_exit(idx); } =20 --=20 2.35.1