* [PATCH] drm/ttm: Add NULL check in ttm_resource_manager_usage
@ 2025-10-13 1:54 Jesse.Zhang
2025-10-13 4:36 ` Lazar, Lijo
0 siblings, 1 reply; 6+ messages in thread
From: Jesse.Zhang @ 2025-10-13 1:54 UTC (permalink / raw)
To: amd-gfx, dri-devel
Cc: Alexander.Deucher, Christian Koenig, Jesse.Zhang, Philip Yang,
Jesse Zhang
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
^ permalink raw reply related [flat|nested] 6+ messages in thread* RE: [PATCH] drm/ttm: Add NULL check in ttm_resource_manager_usage 2025-10-13 1:54 [PATCH] drm/ttm: Add NULL check in ttm_resource_manager_usage Jesse.Zhang @ 2025-10-13 4:36 ` Lazar, Lijo 2025-10-13 5:55 ` Zhang, Jesse(Jie) 0 siblings, 1 reply; 6+ messages in thread From: Lazar, Lijo @ 2025-10-13 4:36 UTC (permalink / raw) To: Zhang, Jesse(Jie), amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Cc: Deucher, Alexander, Koenig, Christian, Zhang, Jesse(Jie), Yang, Philip, Zhang, Jesse(Jie) [AMD Official Use Only - AMD Internal Distribution Only] The specific issue of trace with amdgpu_mem_info_vram_used_show should be fixed with this one - "drm/amdgpu: hide VRAM sysfs attributes on GPUs without VRAM" Thanks, Lijo >-----Original Message----- >From: amd-gfx <amd-gfx-bounces@lists.freedesktop.org> On Behalf Of >Jesse.Zhang >Sent: Monday, October 13, 2025 7:25 AM >To: amd-gfx@lists.freedesktop.org; dri-devel@lists.freedesktop.org >Cc: Deucher, Alexander <Alexander.Deucher@amd.com>; Koenig, Christian ><Christian.Koenig@amd.com>; Zhang, Jesse(Jie) <Jesse.Zhang@amd.com>; >Yang, Philip <Philip.Yang@amd.com>; Zhang, Jesse(Jie) ><Jesse.Zhang@amd.com> >Subject: [PATCH] drm/ttm: Add NULL check in ttm_resource_manager_usage > >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 ^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [PATCH] drm/ttm: Add NULL check in ttm_resource_manager_usage 2025-10-13 4:36 ` Lazar, Lijo @ 2025-10-13 5:55 ` Zhang, Jesse(Jie) 2025-10-13 7:09 ` Lazar, Lijo 0 siblings, 1 reply; 6+ messages in thread From: Zhang, Jesse(Jie) @ 2025-10-13 5:55 UTC (permalink / raw) To: Lazar, Lijo, amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Cc: Deucher, Alexander, Koenig, Christian, Yang, Philip [AMD Official Use Only - AMD Internal Distribution Only] > -----Original Message----- > From: Lazar, Lijo <Lijo.Lazar@amd.com> > Sent: Monday, October 13, 2025 12:37 PM > To: Zhang, Jesse(Jie) <Jesse.Zhang@amd.com>; amd-gfx@lists.freedesktop.org; > dri-devel@lists.freedesktop.org > Cc: Deucher, Alexander <Alexander.Deucher@amd.com>; Koenig, Christian > <Christian.Koenig@amd.com>; Zhang, Jesse(Jie) <Jesse.Zhang@amd.com>; > Yang, Philip <Philip.Yang@amd.com>; Zhang, Jesse(Jie) > <Jesse.Zhang@amd.com> > Subject: RE: [PATCH] drm/ttm: Add NULL check in ttm_resource_manager_usage > > [AMD Official Use Only - AMD Internal Distribution Only] > > The specific issue of trace with amdgpu_mem_info_vram_used_show should be > fixed with this one - "drm/amdgpu: hide VRAM sysfs attributes on GPUs without > VRAM" Thanks @Lazar, Lijo, maybe we still can use this patch to fix this crash when calling AMDGPU_CS and query AMDGPU_INFO_VRAM_USAGE. or add check like the previous patch. Regards Jesse [ 911.954646] BUG: kernel NULL pointer dereference, address: 00000000000008f8 [ 911.962437] #PF: supervisor write access in kernel mode [ 912.007045] RIP: 0010:_raw_spin_lock+0x1e/0x40 [ 912.105151] amdttm_resource_manager_usage+0x1f/0x40 [amdttm] [ 912.111579] amdgpu_cs_parser_bos.isra.0+0x543/0x800 [amdgpu] > > Thanks, > Lijo > >-----Original Message----- > >From: amd-gfx <amd-gfx-bounces@lists.freedesktop.org> On Behalf Of > >Jesse.Zhang > >Sent: Monday, October 13, 2025 7:25 AM > >To: amd-gfx@lists.freedesktop.org; dri-devel@lists.freedesktop.org > >Cc: Deucher, Alexander <Alexander.Deucher@amd.com>; Koenig, Christian > ><Christian.Koenig@amd.com>; Zhang, Jesse(Jie) <Jesse.Zhang@amd.com>; > >Yang, Philip <Philip.Yang@amd.com>; Zhang, Jesse(Jie) > ><Jesse.Zhang@amd.com> > >Subject: [PATCH] drm/ttm: Add NULL check in ttm_resource_manager_usage > > > >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 > ^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [PATCH] drm/ttm: Add NULL check in ttm_resource_manager_usage 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 0 siblings, 2 replies; 6+ messages in thread From: Lazar, Lijo @ 2025-10-13 7:09 UTC (permalink / raw) To: Zhang, Jesse(Jie), amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Cc: Deucher, Alexander, Koenig, Christian, Yang, Philip [AMD Official Use Only - AMD Internal Distribution Only] >-----Original Message----- >From: Zhang, Jesse(Jie) <Jesse.Zhang@amd.com> >Sent: Monday, October 13, 2025 11:25 AM >To: Lazar, Lijo <Lijo.Lazar@amd.com>; amd-gfx@lists.freedesktop.org; dri- >devel@lists.freedesktop.org >Cc: Deucher, Alexander <Alexander.Deucher@amd.com>; Koenig, Christian ><Christian.Koenig@amd.com>; Yang, Philip <Philip.Yang@amd.com> >Subject: RE: [PATCH] drm/ttm: Add NULL check in >ttm_resource_manager_usage > >[AMD Official Use Only - AMD Internal Distribution Only] > >> -----Original Message----- >> From: Lazar, Lijo <Lijo.Lazar@amd.com> >> Sent: Monday, October 13, 2025 12:37 PM >> To: Zhang, Jesse(Jie) <Jesse.Zhang@amd.com>; >> amd-gfx@lists.freedesktop.org; dri-devel@lists.freedesktop.org >> Cc: Deucher, Alexander <Alexander.Deucher@amd.com>; Koenig, Christian >> <Christian.Koenig@amd.com>; Zhang, Jesse(Jie) <Jesse.Zhang@amd.com>; >> Yang, Philip <Philip.Yang@amd.com>; Zhang, Jesse(Jie) >> <Jesse.Zhang@amd.com> >> Subject: RE: [PATCH] drm/ttm: Add NULL check in >> ttm_resource_manager_usage >> >> [AMD Official Use Only - AMD Internal Distribution Only] >> >> The specific issue of trace with amdgpu_mem_info_vram_used_show should >> be fixed with this one - "drm/amdgpu: hide VRAM sysfs attributes on >> GPUs without VRAM" >Thanks @Lazar, Lijo, maybe we still can use this patch to fix this crash when >calling AMDGPU_CS and query AMDGPU_INFO_VRAM_USAGE. >or add check like the previous patch. > [lijo] Agree, there are indeed multiple places of ttm_resource_manager_usage call. You may follow the same check as in the hide VRAM patch - ttm_resource_manager_used - in case ttm doesn't take this change. Thanks, Lijo >Regards >Jesse > >[ 911.954646] BUG: kernel NULL pointer dereference, address: >00000000000008f8 [ 911.962437] >#PF: supervisor write access in kernel mode [ 912.007045] RIP: >0010:_raw_spin_lock+0x1e/0x40 [ 912.105151] >amdttm_resource_manager_usage+0x1f/0x40 > [amdttm] [ 912.111579] amdgpu_cs_parser_bos.isra.0+0x543/0x800 >[amdgpu] > >> >> Thanks, >> Lijo >> >-----Original Message----- >> >From: amd-gfx <amd-gfx-bounces@lists.freedesktop.org> On Behalf Of >> >Jesse.Zhang >> >Sent: Monday, October 13, 2025 7:25 AM >> >To: amd-gfx@lists.freedesktop.org; dri-devel@lists.freedesktop.org >> >Cc: Deucher, Alexander <Alexander.Deucher@amd.com>; Koenig, Christian >> ><Christian.Koenig@amd.com>; Zhang, Jesse(Jie) <Jesse.Zhang@amd.com>; >> >Yang, Philip <Philip.Yang@amd.com>; Zhang, Jesse(Jie) >> ><Jesse.Zhang@amd.com> >> >Subject: [PATCH] drm/ttm: Add NULL check in >> >ttm_resource_manager_usage >> > >> >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 >> > ^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [PATCH] drm/ttm: Add NULL check in ttm_resource_manager_usage 2025-10-13 7:09 ` Lazar, Lijo @ 2025-10-13 7:23 ` Lazar, Lijo 2025-10-13 7:28 ` Christian König 1 sibling, 0 replies; 6+ messages in thread From: Lazar, Lijo @ 2025-10-13 7:23 UTC (permalink / raw) To: Lazar, Lijo, Zhang, Jesse(Jie), amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Cc: Deucher, Alexander, Koenig, Christian, Yang, Philip [Public] >-----Original Message----- >From: amd-gfx <amd-gfx-bounces@lists.freedesktop.org> On Behalf Of Lazar, >Lijo >Sent: Monday, October 13, 2025 12:39 PM >To: Zhang, Jesse(Jie) <Jesse.Zhang@amd.com>; amd- >gfx@lists.freedesktop.org; dri-devel@lists.freedesktop.org >Cc: Deucher, Alexander <Alexander.Deucher@amd.com>; Koenig, Christian ><Christian.Koenig@amd.com>; Yang, Philip <Philip.Yang@amd.com> >Subject: RE: [PATCH] drm/ttm: Add NULL check in >ttm_resource_manager_usage > >[AMD Official Use Only - AMD Internal Distribution Only] > >>-----Original Message----- >>From: Zhang, Jesse(Jie) <Jesse.Zhang@amd.com> >>Sent: Monday, October 13, 2025 11:25 AM >>To: Lazar, Lijo <Lijo.Lazar@amd.com>; amd-gfx@lists.freedesktop.org; >>dri- devel@lists.freedesktop.org >>Cc: Deucher, Alexander <Alexander.Deucher@amd.com>; Koenig, Christian >><Christian.Koenig@amd.com>; Yang, Philip <Philip.Yang@amd.com> >>Subject: RE: [PATCH] drm/ttm: Add NULL check in >>ttm_resource_manager_usage >> >>[AMD Official Use Only - AMD Internal Distribution Only] >> >>> -----Original Message----- >>> From: Lazar, Lijo <Lijo.Lazar@amd.com> >>> Sent: Monday, October 13, 2025 12:37 PM >>> To: Zhang, Jesse(Jie) <Jesse.Zhang@amd.com>; >>> amd-gfx@lists.freedesktop.org; dri-devel@lists.freedesktop.org >>> Cc: Deucher, Alexander <Alexander.Deucher@amd.com>; Koenig, Christian >>> <Christian.Koenig@amd.com>; Zhang, Jesse(Jie) <Jesse.Zhang@amd.com>; >>> Yang, Philip <Philip.Yang@amd.com>; Zhang, Jesse(Jie) >>> <Jesse.Zhang@amd.com> >>> Subject: RE: [PATCH] drm/ttm: Add NULL check in >>> ttm_resource_manager_usage >>> >>> [AMD Official Use Only - AMD Internal Distribution Only] >>> >>> The specific issue of trace with amdgpu_mem_info_vram_used_show >>> should be fixed with this one - "drm/amdgpu: hide VRAM sysfs >>> attributes on GPUs without VRAM" >>Thanks @Lazar, Lijo, maybe we still can use this patch to fix this >>crash when calling AMDGPU_CS and query AMDGPU_INFO_VRAM_USAGE. >>or add check like the previous patch. >> >[lijo] > >Agree, there are indeed multiple places of ttm_resource_manager_usage call. >You may follow the same check as in the hide VRAM patch - >ttm_resource_manager_used - in case ttm doesn't take this change. > On a second look, struct amdgpu_vram_mgr { struct ttm_resource_manager manager; Hence this won't work for something like this - case AMDGPU_INFO_VRAM_USAGE: ui64 = ttm_resource_manager_usage(&adev->mman.vram_mgr.manager); Thanks, Lijo >Thanks, >Lijo > >>Regards >>Jesse >> >>[ 911.954646] BUG: kernel NULL pointer dereference, address: >>00000000000008f8 [ 911.962437] >>#PF: supervisor write access in kernel mode [ 912.007045] RIP: >>0010:_raw_spin_lock+0x1e/0x40 [ 912.105151] >>amdttm_resource_manager_usage+0x1f/0x40 >> [amdttm] [ 912.111579] amdgpu_cs_parser_bos.isra.0+0x543/0x800 >>[amdgpu] >> >>> >>> Thanks, >>> Lijo >>> >-----Original Message----- >>> >From: amd-gfx <amd-gfx-bounces@lists.freedesktop.org> On Behalf Of >>> >Jesse.Zhang >>> >Sent: Monday, October 13, 2025 7:25 AM >>> >To: amd-gfx@lists.freedesktop.org; dri-devel@lists.freedesktop.org >>> >Cc: Deucher, Alexander <Alexander.Deucher@amd.com>; Koenig, >>> >Christian <Christian.Koenig@amd.com>; Zhang, Jesse(Jie) >>> ><Jesse.Zhang@amd.com>; Yang, Philip <Philip.Yang@amd.com>; Zhang, >>> >Jesse(Jie) <Jesse.Zhang@amd.com> >>> >Subject: [PATCH] drm/ttm: Add NULL check in >>> >ttm_resource_manager_usage >>> > >>> >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 >>> >> ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] drm/ttm: Add NULL check in ttm_resource_manager_usage 2025-10-13 7:09 ` Lazar, Lijo 2025-10-13 7:23 ` Lazar, Lijo @ 2025-10-13 7:28 ` Christian König 1 sibling, 0 replies; 6+ messages in thread From: Christian König @ 2025-10-13 7:28 UTC (permalink / raw) To: Lazar, Lijo, Zhang, Jesse(Jie), amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org Cc: Deucher, Alexander, Yang, Philip On 13.10.25 09:09, Lazar, Lijo wrote: > [AMD Official Use Only - AMD Internal Distribution Only] > >> -----Original Message----- >> From: Zhang, Jesse(Jie) <Jesse.Zhang@amd.com> >> Sent: Monday, October 13, 2025 11:25 AM >> To: Lazar, Lijo <Lijo.Lazar@amd.com>; amd-gfx@lists.freedesktop.org; dri- >> devel@lists.freedesktop.org >> Cc: Deucher, Alexander <Alexander.Deucher@amd.com>; Koenig, Christian >> <Christian.Koenig@amd.com>; Yang, Philip <Philip.Yang@amd.com> >> Subject: RE: [PATCH] drm/ttm: Add NULL check in >> ttm_resource_manager_usage >> >> [AMD Official Use Only - AMD Internal Distribution Only] >> >>> -----Original Message----- >>> From: Lazar, Lijo <Lijo.Lazar@amd.com> >>> Sent: Monday, October 13, 2025 12:37 PM >>> To: Zhang, Jesse(Jie) <Jesse.Zhang@amd.com>; >>> amd-gfx@lists.freedesktop.org; dri-devel@lists.freedesktop.org >>> Cc: Deucher, Alexander <Alexander.Deucher@amd.com>; Koenig, Christian >>> <Christian.Koenig@amd.com>; Zhang, Jesse(Jie) <Jesse.Zhang@amd.com>; >>> Yang, Philip <Philip.Yang@amd.com>; Zhang, Jesse(Jie) >>> <Jesse.Zhang@amd.com> >>> Subject: RE: [PATCH] drm/ttm: Add NULL check in >>> ttm_resource_manager_usage >>> >>> [AMD Official Use Only - AMD Internal Distribution Only] >>> >>> The specific issue of trace with amdgpu_mem_info_vram_used_show should >>> be fixed with this one - "drm/amdgpu: hide VRAM sysfs attributes on >>> GPUs without VRAM" >> Thanks @Lazar, Lijo, maybe we still can use this patch to fix this crash when >> calling AMDGPU_CS and query AMDGPU_INFO_VRAM_USAGE. >> or add check like the previous patch. >> > [lijo] > > Agree, there are indeed multiple places of ttm_resource_manager_usage call. You may follow the same check as in the hide VRAM patch - ttm_resource_manager_used - in case ttm doesn't take this change. Yeah, agree. When the VRAM manager isn't initialized we shouldn't be calling any of its functions in the first place. Maybe it is a good idea to add something like "if (WARN_ON_ONCE(!man)) return 0;" to prevent the crashes and only get a nice warning into the system log. Regards, Christian. > > Thanks, > Lijo > >> Regards >> Jesse >> >> [ 911.954646] BUG: kernel NULL pointer dereference, address: >> 00000000000008f8 [ 911.962437] >> #PF: supervisor write access in kernel mode [ 912.007045] RIP: >> 0010:_raw_spin_lock+0x1e/0x40 [ 912.105151] >> amdttm_resource_manager_usage+0x1f/0x40 >> [amdttm] [ 912.111579] amdgpu_cs_parser_bos.isra.0+0x543/0x800 >> [amdgpu] >> >>> >>> Thanks, >>> Lijo >>>> -----Original Message----- >>>> From: amd-gfx <amd-gfx-bounces@lists.freedesktop.org> On Behalf Of >>>> Jesse.Zhang >>>> Sent: Monday, October 13, 2025 7:25 AM >>>> To: amd-gfx@lists.freedesktop.org; dri-devel@lists.freedesktop.org >>>> Cc: Deucher, Alexander <Alexander.Deucher@amd.com>; Koenig, Christian >>>> <Christian.Koenig@amd.com>; Zhang, Jesse(Jie) <Jesse.Zhang@amd.com>; >>>> Yang, Philip <Philip.Yang@amd.com>; Zhang, Jesse(Jie) >>>> <Jesse.Zhang@amd.com> >>>> Subject: [PATCH] drm/ttm: Add NULL check in >>>> ttm_resource_manager_usage >>>> >>>> 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 >>> >> > ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-10-13 7:29 UTC | newest] Thread overview: 6+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-10-13 1:54 [PATCH] drm/ttm: Add NULL check in ttm_resource_manager_usage Jesse.Zhang 2025-10-13 4:36 ` 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
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox