Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3013042rwb; Mon, 15 Aug 2022 16:08:45 -0700 (PDT) X-Google-Smtp-Source: AA6agR6N9qXKNfwYW7mAecclqEJXk5YlcsMrSNNpxjoklv2efeCtUXXql/n0mviTa7p/PRv4TwCh X-Received: by 2002:a17:906:5a5f:b0:731:8586:7904 with SMTP id my31-20020a1709065a5f00b0073185867904mr11587100ejc.559.1660604924963; Mon, 15 Aug 2022 16:08:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660604924; cv=none; d=google.com; s=arc-20160816; b=aEnAiac0eF+4jwnIcOPaZLLUoE8Q6QRJOIEBT//ypXsVXreYDYKHD9twQAUWMV8xYj xUnxUY/5mx/iEIDYFUWgnA3BHnyubYHa4cj8B5EuDPInejsvnMANYExbULvSZ2Jt78ie M9fAh/5oPUGATVJhZmbSEFKTg5P6huxzXjgivGCJd0sZnMdTOtDFn0RAkBwm2By4gvjb sTYJm2r3X3IZ0LLZni5Ow4Oz2014ocVWKAOLwiZ1CTe2IZJu5+/KmfHIhTKNgE+hVK5n xP1maSxOSy/DCeyfdVAZjdXrADWorQUOBqv+RPtzjj54rUb11l4lClX3e5UCTBxiiz77 a/Og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=8sq/NA5tWSD4KIexkZn4kLvyhjW448NSPiQy6Z35ojA=; b=RLMd3QqYb8QEoOCMg2zmXI6cl81B0XHPAkbrtItevTL7xlnSYyIksQmAWL/rASi9m0 rs5XcQsovU9rwmyoI8+rnZt1fgdZ032Fl2RILlZPlAu6rzjoLxAe/UMk5YQAj+JT4UGH s5vRqjJaPmriXL2vpars9Kg+9Ew7ZcI9MW5DmbL4taIY/dib5UbphTyx0p9CghWFGGFj TC6FCSfOZyaNM6KpUNarsmnt4lmuBNRFYF4GbcLjF2M40fO4oc9gMQetJky9UWhFNXgS VvvIxixGYiSjF65MBxWTt5cMXSxUhpkU26UgS0cXGq1Df3IRLkBELQoIK1VN4hiUynHD 3OCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="pF63v/cT"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cw9-20020a170906478900b0072b61694e92si10455047ejc.350.2022.08.15.16.08.19; Mon, 15 Aug 2022 16:08:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="pF63v/cT"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344587AbiHOVRc (ORCPT + 99 others); Mon, 15 Aug 2022 17:17:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348097AbiHOVIH (ORCPT ); Mon, 15 Aug 2022 17:08:07 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 76C0E52E58; Mon, 15 Aug 2022 12:18:25 -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 sin.source.kernel.org (Postfix) with ESMTPS id E2784CE12C5; Mon, 15 Aug 2022 19:18:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E54F3C433D6; Mon, 15 Aug 2022 19:18:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660591102; bh=5kYBB6X/8iRDlgaDFIsv3QBoZ6DilMJxaXnfoQdzZXk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pF63v/cTNnt0I+aZmVmDUqOQcOkFLjIzFF0XDirpC++A3vQloCrHmBEhmk83q97rO FKmbrKcIgtplR8ghwEkI5m7ankaC4qOJ2zgGPaPIbzoKr22Sg3+S4+XhtYbkI+MTvJ tQG/SYhqbfYUtDN+GJXn6YFlwCsbdE8C/mJ22dUk= 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.18 0473/1095] drm/amdgpu: restore original stable pstate on ctx fini Date: Mon, 15 Aug 2022 19:57:52 +0200 Message-Id: <20220815180449.144415984@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180429.240518113@linuxfoundation.org> References: <20220815180429.240518113@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 a61e4c83a545..95ed528e6ec5 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ctx.c @@ -220,32 +220,6 @@ static int amdgpu_ctx_init_entity(struct amdgpu_ctx *ctx, u32 hw_ip, return r; } -static int amdgpu_ctx_init(struct amdgpu_ctx_mgr *mgr, int32_t priority, - struct drm_file *filp, struct amdgpu_ctx *ctx) -{ - int r; - - r = amdgpu_ctx_priority_permit(filp, priority); - if (r) - return r; - - memset(ctx, 0, sizeof(*ctx)); - - kref_init(&ctx->refcount); - ctx->mgr = mgr; - spin_lock_init(&ctx->ring_lock); - mutex_init(&ctx->lock); - - ctx->reset_counter = atomic_read(&mgr->adev->gpu_reset_counter); - ctx->reset_counter_query = ctx->reset_counter; - ctx->vram_lost_counter = atomic_read(&mgr->adev->vram_lost_counter); - ctx->init_priority = priority; - ctx->override_priority = AMDGPU_CTX_PRIORITY_UNSET; - ctx->stable_pstate = AMDGPU_CTX_STABLE_PSTATE_NONE; - - return 0; -} - static void amdgpu_ctx_fini_entity(struct amdgpu_ctx_entity *entity) { @@ -288,6 +262,38 @@ static int amdgpu_ctx_get_stable_pstate(struct amdgpu_ctx *ctx, return 0; } +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 = amdgpu_ctx_priority_permit(filp, priority); + if (r) + return r; + + memset(ctx, 0, sizeof(*ctx)); + + kref_init(&ctx->refcount); + ctx->mgr = mgr; + spin_lock_init(&ctx->ring_lock); + mutex_init(&ctx->lock); + + ctx->reset_counter = atomic_read(&mgr->adev->gpu_reset_counter); + ctx->reset_counter_query = ctx->reset_counter; + ctx->vram_lost_counter = atomic_read(&mgr->adev->vram_lost_counter); + ctx->init_priority = priority; + ctx->override_priority = AMDGPU_CTX_PRIORITY_UNSET; + + r = amdgpu_ctx_get_stable_pstate(ctx, ¤t_stable_pstate); + if (r) + return r; + + ctx->stable_pstate = current_stable_pstate; + + return 0; +} + static int amdgpu_ctx_set_stable_pstate(struct amdgpu_ctx *ctx, u32 stable_pstate) { @@ -357,7 +363,7 @@ static void amdgpu_ctx_fini(struct kref *ref) } 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); } -- 2.35.1