The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] fix: drm/vmwgfx: vmw_user_shader_alloc: fix base object refcount leak on   ttm_base_object_init failure
@ 2026-06-26 15:01 WenTao Liang
  2026-06-28  4:03 ` WenTao Liang
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: WenTao Liang @ 2026-06-26 15:01 UTC (permalink / raw)
  To: Zack Rusin, dri-devel
  Cc: bcm-kernel-feedback-list, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, Thomas Hellstrom,
	stable, linux-kernel, WenTao Liang

ttm_base_object_init unconditionally acquires a base object reference via
  kref_init. When it fails, the error path in vmw_user_shader_alloc only
  calls vmw_resource_unreference but never calls ttm_base_object_unref to
  release the base object reference, causing a refcount leak.

Add ttm_base_object_unref in the error path to properly release the base
  object reference when ttm_base_object_init fails.

Cc: stable@vger.kernel.org
Fixes: 0b8762e997df ("drm/ttm, drm/vmwgfx: Move the lock- and object functionality to the vmwgfx driver")
Signed-off-by: WenTao Liang <vulab@iscas.ac.cn>
---
 drivers/gpu/drm/vmwgfx/vmwgfx_shader.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c b/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c
index eca4e3e97eb4..d82ec43c8901 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c
@@ -724,6 +724,7 @@ static int vmw_user_shader_alloc(struct vmw_private *dev_priv,
 
 	if (unlikely(ret != 0)) {
 		vmw_resource_unreference(&tmp);
+		ttm_base_object_unref(&ushader->base);
 		goto out_err;
 	}
 
-- 
2.39.5 (Apple Git-154)


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] fix: drm/vmwgfx: vmw_user_shader_alloc: fix base object refcount leak on   ttm_base_object_init failure
  2026-06-26 15:01 [PATCH] fix: drm/vmwgfx: vmw_user_shader_alloc: fix base object refcount leak on ttm_base_object_init failure WenTao Liang
@ 2026-06-28  4:03 ` WenTao Liang
  2026-08-07 20:24 ` kernel test robot
  2026-08-08  0:58 ` kernel test robot
  2 siblings, 0 replies; 4+ messages in thread
From: WenTao Liang @ 2026-06-28  4:03 UTC (permalink / raw)
  To: Zack Rusin, dri-devel
  Cc: bcm-kernel-feedback-list, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, David Airlie, Simona Vetter, Thomas Hellstrom,
	stable, linux-kernel



> 2026年6月26日 23:01,WenTao Liang <vulab@iscas.ac.cn> 写道:
> 
> ttm_base_object_init unconditionally acquires a base object reference via
>  kref_init. When it fails, the error path in vmw_user_shader_alloc only
>  calls vmw_resource_unreference but never calls ttm_base_object_unref to
>  release the base object reference, causing a refcount leak.
> 
> Add ttm_base_object_unref in the error path to properly release the base
>  object reference when ttm_base_object_init fails.
> 
> Cc: stable@vger.kernel.org
> Fixes: 0b8762e997df ("drm/ttm, drm/vmwgfx: Move the lock- and object functionality to the vmwgfx driver")
> Signed-off-by: WenTao Liang <vulab@iscas.ac.cn>
> ---
> drivers/gpu/drm/vmwgfx/vmwgfx_shader.c | 1 +
> 1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c b/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c
> index eca4e3e97eb4..d82ec43c8901 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_shader.c
> @@ -724,6 +724,7 @@ static int vmw_user_shader_alloc(struct vmw_private *dev_priv,
> 
> 	if (unlikely(ret != 0)) {
> 		vmw_resource_unreference(&tmp);
> +		ttm_base_object_unref(&ushader->base);
> 		goto out_err;
> 	}
> 
> -- 
> 2.39.5 (Apple Git-154)

Please ignore this patch. I will resend a proper version after
learning the kernel submission process.

Apologies for the noise.

Best regards,
WenTao Liang

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] fix: drm/vmwgfx: vmw_user_shader_alloc: fix base object refcount leak on ttm_base_object_init failure
  2026-06-26 15:01 [PATCH] fix: drm/vmwgfx: vmw_user_shader_alloc: fix base object refcount leak on ttm_base_object_init failure WenTao Liang
  2026-06-28  4:03 ` WenTao Liang
@ 2026-08-07 20:24 ` kernel test robot
  2026-08-08  0:58 ` kernel test robot
  2 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2026-08-07 20:24 UTC (permalink / raw)
  To: WenTao Liang, Zack Rusin, dri-devel
  Cc: oe-kbuild-all, bcm-kernel-feedback-list, Maarten Lankhorst,
	Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter,
	Thomas Hellstrom, stable, linux-kernel, WenTao Liang

Hi WenTao,

kernel test robot noticed the following build errors:

[auto build test ERROR on drm-misc/drm-misc-next]
[also build test ERROR on daeinki-drm-exynos/exynos-drm-next drm/drm-next drm-i915/for-linux-next drm-i915/for-linux-next-fixes drm-tip/drm-tip linus/master v7.2-rc6 next-20260806]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/WenTao-Liang/fix-drm-vmwgfx-vmw_user_shader_alloc-fix-base-object-refcount-leak-on-ttm_base_object_init-failure/20260807-080356
base:   https://gitlab.freedesktop.org/drm/misc/kernel.git drm-misc-next
patch link:    https://lore.kernel.org/r/20260626150142.49732-1-vulab%40iscas.ac.cn
patch subject: [PATCH] fix: drm/vmwgfx: vmw_user_shader_alloc: fix base object refcount leak on ttm_base_object_init failure
config: i386-allmodconfig (https://download.01.org/0day-ci/archive/20260808/202608080444.GqlrPBjd-lkp@intel.com/config)
compiler: gcc-14 (Debian 14.2.0-19) 14.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260808/202608080444.GqlrPBjd-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202608080444.GqlrPBjd-lkp@intel.com/

All errors (new ones prefixed by >>):

   drivers/gpu/drm/vmwgfx/vmwgfx_shader.c: In function 'vmw_user_shader_alloc':
>> drivers/gpu/drm/vmwgfx/vmwgfx_shader.c:727:39: error: passing argument 1 of 'ttm_base_object_unref' from incompatible pointer type [-Wincompatible-pointer-types]
     727 |                 ttm_base_object_unref(&ushader->base);
         |                                       ^~~~~~~~~~~~~~
         |                                       |
         |                                       struct ttm_base_object *
   In file included from drivers/gpu/drm/vmwgfx/vmwgfx_drv.h:27,
                    from drivers/gpu/drm/vmwgfx/vmwgfx_shader.c:32:
   drivers/gpu/drm/vmwgfx/ttm_object.h:192:60: note: expected 'struct ttm_base_object **' but argument is of type 'struct ttm_base_object *'
     192 | extern void ttm_base_object_unref(struct ttm_base_object **p_base);
         |                                   ~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~


vim +/ttm_base_object_unref +727 drivers/gpu/drm/vmwgfx/vmwgfx_shader.c

   684	
   685	static int vmw_user_shader_alloc(struct vmw_private *dev_priv,
   686					 struct vmw_bo *buffer,
   687					 size_t shader_size,
   688					 size_t offset,
   689					 SVGA3dShaderType shader_type,
   690					 uint8_t num_input_sig,
   691					 uint8_t num_output_sig,
   692					 struct ttm_object_file *tfile,
   693					 u32 *handle)
   694	{
   695		struct vmw_user_shader *ushader;
   696		struct vmw_resource *res, *tmp;
   697		int ret;
   698	
   699		ushader = kzalloc_obj(*ushader);
   700		if (unlikely(!ushader)) {
   701			ret = -ENOMEM;
   702			goto out;
   703		}
   704	
   705		res = &ushader->shader.res;
   706		ushader->base.shareable = false;
   707		ushader->base.tfile = NULL;
   708	
   709		/*
   710		 * From here on, the destructor takes over resource freeing.
   711		 */
   712	
   713		ret = vmw_gb_shader_init(dev_priv, res, shader_size,
   714					 offset, shader_type, num_input_sig,
   715					 num_output_sig, buffer,
   716					 vmw_user_shader_free);
   717		if (unlikely(ret != 0))
   718			goto out;
   719	
   720		tmp = vmw_resource_reference(res);
   721		ret = ttm_base_object_init(tfile, &ushader->base, false,
   722					   VMW_RES_SHADER,
   723					   &vmw_user_shader_base_release);
   724	
   725		if (unlikely(ret != 0)) {
   726			vmw_resource_unreference(&tmp);
 > 727			ttm_base_object_unref(&ushader->base);
   728			goto out_err;
   729		}
   730	
   731		if (handle)
   732			*handle = ushader->base.handle;
   733	out_err:
   734		vmw_resource_unreference(&res);
   735	out:
   736		return ret;
   737	}
   738	

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] fix: drm/vmwgfx: vmw_user_shader_alloc: fix base object refcount leak on ttm_base_object_init failure
  2026-06-26 15:01 [PATCH] fix: drm/vmwgfx: vmw_user_shader_alloc: fix base object refcount leak on ttm_base_object_init failure WenTao Liang
  2026-06-28  4:03 ` WenTao Liang
  2026-08-07 20:24 ` kernel test robot
@ 2026-08-08  0:58 ` kernel test robot
  2 siblings, 0 replies; 4+ messages in thread
From: kernel test robot @ 2026-08-08  0:58 UTC (permalink / raw)
  To: WenTao Liang, Zack Rusin, dri-devel
  Cc: llvm, oe-kbuild-all, bcm-kernel-feedback-list, Maarten Lankhorst,
	Maxime Ripard, Thomas Zimmermann, David Airlie, Simona Vetter,
	Thomas Hellstrom, stable, linux-kernel, WenTao Liang

Hi WenTao,

kernel test robot noticed the following build errors:

[auto build test ERROR on drm-misc/drm-misc-next]
[also build test ERROR on daeinki-drm-exynos/exynos-drm-next drm/drm-next drm-i915/for-linux-next drm-i915/for-linux-next-fixes drm-tip/drm-tip linus/master v7.2-rc6 next-20260807]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/WenTao-Liang/fix-drm-vmwgfx-vmw_user_shader_alloc-fix-base-object-refcount-leak-on-ttm_base_object_init-failure/20260807-080356
base:   https://gitlab.freedesktop.org/drm/misc/kernel.git drm-misc-next
patch link:    https://lore.kernel.org/r/20260626150142.49732-1-vulab%40iscas.ac.cn
patch subject: [PATCH] fix: drm/vmwgfx: vmw_user_shader_alloc: fix base object refcount leak on ttm_base_object_init failure
config: arm64-randconfig-002-20260807 (https://download.01.org/0day-ci/archive/20260808/202608080849.rqxWdd9U-lkp@intel.com/config)
compiler: clang version 24.0.0git (https://github.com/llvm/llvm-project 12df34b8469b8095359de8c249cb1b2753fadeea)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260808/202608080849.rqxWdd9U-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202608080849.rqxWdd9U-lkp@intel.com/

All errors (new ones prefixed by >>):

>> drivers/gpu/drm/vmwgfx/vmwgfx_shader.c:727:25: error: incompatible pointer types passing 'struct ttm_base_object *' to parameter of type 'struct ttm_base_object **' [-Wincompatible-pointer-types]
     727 |                 ttm_base_object_unref(&ushader->base);
         |                                       ^~~~~~~~~~~~~~
   drivers/gpu/drm/vmwgfx/ttm_object.h:192:60: note: passing argument to parameter 'p_base' here
     192 | extern void ttm_base_object_unref(struct ttm_base_object **p_base);
         |                                                            ^
   1 error generated.


vim +727 drivers/gpu/drm/vmwgfx/vmwgfx_shader.c

   684	
   685	static int vmw_user_shader_alloc(struct vmw_private *dev_priv,
   686					 struct vmw_bo *buffer,
   687					 size_t shader_size,
   688					 size_t offset,
   689					 SVGA3dShaderType shader_type,
   690					 uint8_t num_input_sig,
   691					 uint8_t num_output_sig,
   692					 struct ttm_object_file *tfile,
   693					 u32 *handle)
   694	{
   695		struct vmw_user_shader *ushader;
   696		struct vmw_resource *res, *tmp;
   697		int ret;
   698	
   699		ushader = kzalloc_obj(*ushader);
   700		if (unlikely(!ushader)) {
   701			ret = -ENOMEM;
   702			goto out;
   703		}
   704	
   705		res = &ushader->shader.res;
   706		ushader->base.shareable = false;
   707		ushader->base.tfile = NULL;
   708	
   709		/*
   710		 * From here on, the destructor takes over resource freeing.
   711		 */
   712	
   713		ret = vmw_gb_shader_init(dev_priv, res, shader_size,
   714					 offset, shader_type, num_input_sig,
   715					 num_output_sig, buffer,
   716					 vmw_user_shader_free);
   717		if (unlikely(ret != 0))
   718			goto out;
   719	
   720		tmp = vmw_resource_reference(res);
   721		ret = ttm_base_object_init(tfile, &ushader->base, false,
   722					   VMW_RES_SHADER,
   723					   &vmw_user_shader_base_release);
   724	
   725		if (unlikely(ret != 0)) {
   726			vmw_resource_unreference(&tmp);
 > 727			ttm_base_object_unref(&ushader->base);
   728			goto out_err;
   729		}
   730	
   731		if (handle)
   732			*handle = ushader->base.handle;
   733	out_err:
   734		vmw_resource_unreference(&res);
   735	out:
   736		return ret;
   737	}
   738	

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-08-08  0:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-26 15:01 [PATCH] fix: drm/vmwgfx: vmw_user_shader_alloc: fix base object refcount leak on ttm_base_object_init failure WenTao Liang
2026-06-28  4:03 ` WenTao Liang
2026-08-07 20:24 ` kernel test robot
2026-08-08  0:58 ` kernel test robot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox