Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3851638pxv; Mon, 19 Jul 2021 10:15:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZ54UlZGLDiIWZsQ8cNG83f6UrOprjn++a94eZH6lTZqWn4X4sg3p0uApaXw8XatSl/ThT X-Received: by 2002:a17:907:7709:: with SMTP id kw9mr28874184ejc.68.1626714905412; Mon, 19 Jul 2021 10:15:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626714905; cv=none; d=google.com; s=arc-20160816; b=oG/tjlDNEO9ODIAzCfkG0XFuMIKZ/5aBRkALyi8hZv0Zt7K5CN6/+GA31ND9NQQWUq srg/7UhQS0nKpsls9KNqpP0Q39xWAPNKqxtkfCi+r1OrIrdvQ6vYwUJkYSmwwNqO+94k 4lp4jy24AnwtT+WrqARHBi7+2jAXLcd/JPr//7x15pCa2O3jRzLyk3OoGDz9UZUy71rc PolAgP3M5F/XtIh+LPLAVWPy1FAteeqKo799rgSyHdhvLkW1h72ILThmuRLYnSJRgjo5 jj3hFYkv+mVl8bb0t5FbYeDGGwcIL6fDdkYxYzFVERoPa8UBHS+hT7LpR3FIjxVZx1wc aExg== 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=xYwHffVKzkouKdrAQsMnhFbxefBFkKA7s9p8tFun7E4=; b=R0QyqMRar7NEQeG35mpM9T/ERdv5A3jomjr2QJC7eGM9aAqbmqvBa/ffU5GQkoQYph u6qsReyPOA62HQAvtKD4MJdYnlsqjkzRoy240/nO9nfw9Z4oL5bQmCuZT0uFTlrDdo9j HuVyw56T8CsxAsTj3TZFwGAyEWLxzxo+K4LkudA/6ryAOfy1+RLUdPcYiXMTTx8ETcMJ emPS81oRYIHecQL0fshJy0cTbkdBGC4Yd52edG+bt/x4aF2UaR18MEtKDbBvko/xDIKM ygnue51DkSa1z9cvBmDph4SEfyvsAZzKV6qAHq/WrWIbi5gnLAWJla7znR7NizrrG/ny 0PWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YOj+Qww8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a16si22089032eje.682.2021.07.19.10.14.41; Mon, 19 Jul 2021 10:15:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=YOj+Qww8; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1352510AbhGSQdN (ORCPT + 99 others); Mon, 19 Jul 2021 12:33:13 -0400 Received: from mail.kernel.org ([198.145.29.99]:57556 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347011AbhGSPRm (ORCPT ); Mon, 19 Jul 2021 11:17:42 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 069A8600EF; Mon, 19 Jul 2021 15:57:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626710249; bh=CcTgJfVEmbNFgL0EvxomN/vMbIEdDbKcKAhs6s8IAmo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YOj+Qww8P+cM8Qnb/7f3f50IcmVQX1pjGSKoCM0Ixz5nHHQAwIWqwsqgUjnkvwveF mCXvRfTC2ZMCZK/ewy41V9mnofsJeW+Gak+jD4KCABW7qTp3AJTkQINFGk3VFm0NDE q3u6qP7N60xc8o7UntQWRNQk12MnrMEQFSk86MGg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Philip Yang , Felix Kuehling , Alex Deucher , Sasha Levin Subject: [PATCH 5.10 137/243] drm/amdkfd: fix sysfs kobj leak Date: Mon, 19 Jul 2021 16:52:46 +0200 Message-Id: <20210719144945.337210439@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210719144940.904087935@linuxfoundation.org> References: <20210719144940.904087935@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Philip Yang [ Upstream commit dcdb4d904b4bd3078fe8d4d24b1658560d6078ef ] 3 cases of kobj leak, which causes memory leak: kobj_type must have release() method to free memory from release callback. Don't need NULL default_attrs to init kobj. sysfs files created under kobj_status should be removed with kobj_status as parent kobject. Remove queue sysfs files when releasing queue from process MMU notifier release callback. Signed-off-by: Philip Yang Reviewed-by: Felix Kuehling Signed-off-by: Alex Deucher Signed-off-by: Sasha Levin --- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 14 ++++++-------- .../gpu/drm/amd/amdkfd/kfd_process_queue_manager.c | 1 + 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c b/drivers/gpu/drm/amd/amdkfd/kfd_process.c index 65803e153a22..d243e60c6eef 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c @@ -452,13 +452,9 @@ static const struct sysfs_ops procfs_stats_ops = { .show = kfd_procfs_stats_show, }; -static struct attribute *procfs_stats_attrs[] = { - NULL -}; - static struct kobj_type procfs_stats_type = { .sysfs_ops = &procfs_stats_ops, - .default_attrs = procfs_stats_attrs, + .release = kfd_procfs_kobj_release, }; int kfd_procfs_add_queue(struct queue *q) @@ -973,9 +969,11 @@ static void kfd_process_wq_release(struct work_struct *work) list_for_each_entry(pdd, &p->per_device_data, per_device_list) { sysfs_remove_file(p->kobj, &pdd->attr_vram); sysfs_remove_file(p->kobj, &pdd->attr_sdma); - sysfs_remove_file(p->kobj, &pdd->attr_evict); - if (pdd->dev->kfd2kgd->get_cu_occupancy != NULL) - sysfs_remove_file(p->kobj, &pdd->attr_cu_occupancy); + + sysfs_remove_file(pdd->kobj_stats, &pdd->attr_evict); + if (pdd->dev->kfd2kgd->get_cu_occupancy) + sysfs_remove_file(pdd->kobj_stats, + &pdd->attr_cu_occupancy); kobject_del(pdd->kobj_stats); kobject_put(pdd->kobj_stats); pdd->kobj_stats = NULL; 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 eb1635ac8988..43c07ac2c6fc 100644 --- a/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c @@ -153,6 +153,7 @@ void pqm_uninit(struct process_queue_manager *pqm) if (pqn->q && pqn->q->gws) amdgpu_amdkfd_remove_gws_from_process(pqm->process->kgd_process_info, pqn->q->gws); + kfd_procfs_del_queue(pqn->q); uninit_queue(pqn->q); list_del(&pqn->process_queue_list); kfree(pqn); -- 2.30.2