Received: by 2002:a05:7412:b10a:b0:f3:1519:9f41 with SMTP id az10csp2970166rdb; Mon, 4 Dec 2023 12:36:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IGc20R5TT62C0wpxbI4zdZ0Z+ytp9u/QX26G8CYPTtfobrGgth1U3fKC4qRnH1bb+d7PtTd X-Received: by 2002:a17:90a:d190:b0:285:b940:b292 with SMTP id fu16-20020a17090ad19000b00285b940b292mr198229pjb.7.1701722207892; Mon, 04 Dec 2023 12:36:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701722207; cv=none; d=google.com; s=arc-20160816; b=HuQvJEMOmhZt91M+7hAIoWchh95ZY1jFvv38NFTjeAGTXKx48ExDZdNDvkSU/nDvBK cVIUP21N/a+5CrgPvh6zfQIBGxh1E2iIZhwwaZarl2KGtDwMWeXQEQCDwuuxWR0OoDax x8lHEG7dE5spJYYCo9OCFyyoDNMnCJm3p3f6nBg+7ZxSgxpwIzNXSsIyiZAtD3f5VYE6 5nyxwSORXfd4DDPDNQFy7+dhfRW/i/uRRas0bxRkaU9nlo4TrO1szUu+/vMsMw6sf8Sh ca8X2qygYn5sUtyJcsnUq5vaWWwiOnbD5kl8ncxnkZziEWfoi7OjhkXI/sgbIq/pRGYa DPNQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dXvs+yoLCP6DQIq3uLYauHuYXwjxSJDps3YS/8tRR1M=; fh=nGQRmCQI0Z5o4rtJpiJjCXhfOWSoiVFu/S4x3Z5fsgE=; b=tXpdbn7CeaqXFRY1nZAjfXydqPjbKLHWzn0/VWBp8aXiLVskEzbl6hQf2wNnHSXKhS A4a+gvvYsADl8Wlxua40LOnmTg/9CvlpIJ4S9R97NBDKm/f8l0OJ1iJaXBfN94Mc2Jo0 AzJFCac6fQQKZXrv06hjrW856yOUInZwiC+8t6M3MutgLfxmVr3Wph/+xBXHqXcB9/AR iSkNRJID8lCZvFNcHfgyloOD7fqUOafqO/rpn/aND7ioEH8vB3gL5Sr8E5Q14nA3yxiv IdJVgSFkNZS6qlWPDwN0YOHud29e0bizqNCSQf9qtQLqOPSA6uB/25wUtEwresqVJIRs peqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Q/iSupNO"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id w16-20020a17090a461000b00278eb61c0ebsi3726940pjg.118.2023.12.04.12.36.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Dec 2023 12:36:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="Q/iSupNO"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id D88D5805CDA6; Mon, 4 Dec 2023 12:36:44 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346222AbjLDUg1 (ORCPT + 99 others); Mon, 4 Dec 2023 15:36:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235537AbjLDUgI (ORCPT ); Mon, 4 Dec 2023 15:36:08 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8FCB92712 for ; Mon, 4 Dec 2023 12:34:46 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5F825C433C8; Mon, 4 Dec 2023 20:34:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701722086; bh=kGmYZKKHc1s6cB5eQD5BL2iS9W5aMoe4n0+Po34UR8M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q/iSupNOxv7bi7dV4w6aEkxxc9GfsGdhfhhwAlb1ssPhx3bB1S8bBU7MhhZFGZbqt NEIWHnuhOO/Kzf6i3WBUjrqhqGrHL85tPSeoHaSdbeIzE7e+horYUsqJUlJhVcKYqs NAhstG2oBR9Pw17tSA1FYg10yk6rzhn4RfPabzh6zValHSbIo0iU9AS4otkg47ejvC B+DLSuCKBbwbsQjXybsaHsOBu2z+Ayu/+eIMAovNi6QQBtRaBmI6SUOEvbrToBciS3 IBs2xQfMLFTtVg55GDCZQ1bn2Tn8hoWg600253qXCK8tiiFZ8vtD7OPETaQC4P/Eb0 6LtIjqJPp7bZA== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: ZhenGuo Yin , Felix Kuehling , Alex Deucher , Sasha Levin , christian.koenig@amd.com, Xinhui.Pan@amd.com, airlied@gmail.com, daniel@ffwll.ch, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Subject: [PATCH AUTOSEL 6.6 27/32] drm/amdkfd: Free gang_ctx_bo and wptr_bo in pqm_uninit Date: Mon, 4 Dec 2023 15:32:47 -0500 Message-ID: <20231204203317.2092321-27-sashal@kernel.org> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231204203317.2092321-1-sashal@kernel.org> References: <20231204203317.2092321-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.6.4 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Mon, 04 Dec 2023 12:36:45 -0800 (PST) From: ZhenGuo Yin [ Upstream commit 72838777aa38352e20301e123b97110c456cd38e ] [Why] Memory leaks of gang_ctx_bo and wptr_bo. [How] Free gang_ctx_bo and wptr_bo in pqm_uninit. v2: add a common function pqm_clean_queue_resource to free queue's resources. v3: reset pdd->pqd.num_gws when destorying GWS queue. Reviewed-by: Felix Kuehling Signed-off-by: ZhenGuo Yin Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- .../amd/amdkfd/kfd_process_queue_manager.c | 54 +++++++++++-------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c b/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c index adb5e4bdc0b20..7d0f887d99558 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c @@ -169,16 +169,43 @@ int pqm_init(struct process_queue_manager *pqm, struct kfd_process *p) return 0; } +static void pqm_clean_queue_resource(struct process_queue_manager *pqm, + struct process_queue_node *pqn) +{ + struct kfd_node *dev; + struct kfd_process_device *pdd; + + dev = pqn->q->device; + + pdd = kfd_get_process_device_data(dev, pqm->process); + if (!pdd) { + pr_err("Process device data doesn't exist\n"); + return; + } + + if (pqn->q->gws) { + if (KFD_GC_VERSION(pqn->q->device) != IP_VERSION(9, 4, 3) && + !dev->kfd->shared_resources.enable_mes) + amdgpu_amdkfd_remove_gws_from_process( + pqm->process->kgd_process_info, pqn->q->gws); + pdd->qpd.num_gws = 0; + } + + if (dev->kfd->shared_resources.enable_mes) { + amdgpu_amdkfd_free_gtt_mem(dev->adev, pqn->q->gang_ctx_bo); + if (pqn->q->wptr_bo) + amdgpu_amdkfd_free_gtt_mem(dev->adev, pqn->q->wptr_bo); + } +} + void pqm_uninit(struct process_queue_manager *pqm) { struct process_queue_node *pqn, *next; list_for_each_entry_safe(pqn, next, &pqm->queues, process_queue_list) { - if (pqn->q && pqn->q->gws && - KFD_GC_VERSION(pqn->q->device) != IP_VERSION(9, 4, 3) && - !pqn->q->device->kfd->shared_resources.enable_mes) - amdgpu_amdkfd_remove_gws_from_process(pqm->process->kgd_process_info, - pqn->q->gws); + if (pqn->q) + pqm_clean_queue_resource(pqm, pqn); + kfd_procfs_del_queue(pqn->q); uninit_queue(pqn->q); list_del(&pqn->process_queue_list); @@ -460,22 +487,7 @@ int pqm_destroy_queue(struct process_queue_manager *pqm, unsigned int qid) goto err_destroy_queue; } - if (pqn->q->gws) { - if (KFD_GC_VERSION(pqn->q->device) != IP_VERSION(9, 4, 3) && - !dev->kfd->shared_resources.enable_mes) - amdgpu_amdkfd_remove_gws_from_process( - pqm->process->kgd_process_info, - pqn->q->gws); - pdd->qpd.num_gws = 0; - } - - if (dev->kfd->shared_resources.enable_mes) { - amdgpu_amdkfd_free_gtt_mem(dev->adev, - pqn->q->gang_ctx_bo); - if (pqn->q->wptr_bo) - amdgpu_amdkfd_free_gtt_mem(dev->adev, pqn->q->wptr_bo); - - } + pqm_clean_queue_resource(pqm, pqn); uninit_queue(pqn->q); } -- 2.42.0