AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Jesse.Zhang <Jesse.Zhang@amd.com>
To: <amd-gfx@lists.freedesktop.org>, <dri-devel@lists.freedesktop.org>
Cc: <Alexander.Deucher@amd.com>,
	Christian Koenig <christian.koenig@amd.com>,
	 Jesse.Zhang <Jesse.Zhang@amd.com>,
	Philip Yang <Philip.Yang@amd.com>,
	"Jesse Zhang" <jesse.zhang@amd.com>
Subject: [PATCH] drm/ttm: Add NULL check in ttm_resource_manager_usage
Date: Mon, 13 Oct 2025 09:54:51 +0800	[thread overview]
Message-ID: <20251013015550.1317222-1-Jesse.Zhang@amd.com> (raw)

Add a NULL pointer check in ttm_resource_manager_usage() to prevent
kernel NULL pointer dereferences when the function is called with
an uninitialized resource manager.

This fixes a kernel OOPS observed on APU devices where the VRAM
resource manager is not fully initialized, but various sysfs and
debug interfaces still attempt to query VRAM usage statistics.

The crash backtrace showed:
    BUG: kernel NULL pointer dereference, address: 00000000000008f8
    Call Trace:
     amdttm_resource_manager_usage+0x1f/0x40 [amdttm]
     amdgpu_mem_info_vram_used_show+0x1e/0x40 [amdgpu]
     dev_attr_show+0x1d/0x40
     kernfs_seq_show+0x27/0x30

By returning 0 for NULL managers, we allow callers to safely query
usage information even when the underlying resource manager is not
available, which is the expected behavior for devices without
dedicated VRAM like APUs.

Suggested-by: Philip Yang <Philip.Yang@amd.com>
Signed-off-by: Jesse Zhang <jesse.zhang@amd.com>
---
 drivers/gpu/drm/ttm/ttm_resource.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/gpu/drm/ttm/ttm_resource.c b/drivers/gpu/drm/ttm/ttm_resource.c
index e2c82ad07eb4..e4d45f75e40a 100644
--- a/drivers/gpu/drm/ttm/ttm_resource.c
+++ b/drivers/gpu/drm/ttm/ttm_resource.c
@@ -587,6 +587,9 @@ uint64_t ttm_resource_manager_usage(struct ttm_resource_manager *man)
 {
 	uint64_t usage;
 
+	if (!man)
+		return 0;
+
 	spin_lock(&man->bdev->lru_lock);
 	usage = man->usage;
 	spin_unlock(&man->bdev->lru_lock);
-- 
2.49.0


             reply	other threads:[~2025-10-13  1:56 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-13  1:54 Jesse.Zhang [this message]
2025-10-13  4:36 ` [PATCH] drm/ttm: Add NULL check in ttm_resource_manager_usage Lazar, Lijo
2025-10-13  5:55   ` Zhang, Jesse(Jie)
2025-10-13  7:09     ` Lazar, Lijo
2025-10-13  7:23       ` Lazar, Lijo
2025-10-13  7:28       ` Christian König

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251013015550.1317222-1-Jesse.Zhang@amd.com \
    --to=jesse.zhang@amd.com \
    --cc=Alexander.Deucher@amd.com \
    --cc=Philip.Yang@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox