Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp3086796rwb; Mon, 15 Aug 2022 17:48:26 -0700 (PDT) X-Google-Smtp-Source: AA6agR6GtirlNNDRILcMHwpyPisbQCD/QwRIXeym34b3EptUs5ZZ+vLdySSmsx/e0RjBpqcGs80d X-Received: by 2002:a05:6402:3287:b0:43d:bcda:bd20 with SMTP id f7-20020a056402328700b0043dbcdabd20mr16706732eda.414.1660610905875; Mon, 15 Aug 2022 17:48:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660610905; cv=none; d=google.com; s=arc-20160816; b=1KqhTbyxMy7L7ixC7ZUQQaVJy/6MqufR5etMg4hJyibd2lOp2vMQHu4udlMc24v4nS TUPGIFiZIbK30RQrVo8Xsphb45vo/xVDb8uAUpmav77CYor2G+Yfll6Zi3HAOCej5z4n g0PXjqsQlvcxfA5FMVPep3ugnXATTZDg2C7qVo6r8yujx84OcR/BVwfyhPsHO/8wLvLy 1gIxjcQxvWEsUBQcbZuilRK5xVtsqlzJNIvONk41ZxoLwLo66kV8pBEPHgvjUiSm/qoF HbAMtaJLX6hI3rtKDhasnumY54cmZuWRi//SbyfUzk5uBVWdZZc52MTvip9p1WJs2R09 eQdA== 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=eVQdufZq44NSjYj/UGr9sDIO7z5gGWMmeRNlPirWA10=; b=SSsVVq5Wr8s65JQ2E0SSZdKAnoczpxFlh9N4yBY7T74Uhc4I8KBH4fEAuhxIHIp1yO ETbArwGfyUW/RTKja58zmJTPY0lCZj4zY69czKz5szs6fU9p60KVzZiOuogU8jzxS7vt l/9MHiLodl4tqV0yCGKm2Ztcr/e1Q+NC4wHvuqn0DcBj/d4lB27virYHHQ1fA9wKk+/8 Nm9Ya0yqUXbs+x8AE/oBqTKwFzG3BELJEz5RUjFEqZMUj5LB/0rMZkC+qAOMsr5POPB5 7Hk/j7i1NxiZsd3C/WIpW7MnvK3ggQnc22YFwZc34hquczmW2ChCoLMzU5Eqae3F2PUT YGxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=UlKVdNoN; 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 p10-20020a170906228a00b00718bf486a1csi6773635eja.782.2022.08.15.17.48.00; Mon, 15 Aug 2022 17:48:25 -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=UlKVdNoN; 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 S1350609AbiHOX7w (ORCPT + 99 others); Mon, 15 Aug 2022 19:59:52 -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-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 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_ctx_entity *entity) return res; } -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 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; } +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) { @@ -396,7 +402,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