All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Christian König" <ckoenig.leichtzumerken@gmail.com>
Cc: dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org,
	intel-xe@lists.freedesktop.org
Subject: Re: [PATCH 08/10] drm/i915/gt: Use dma_resv_alloc for VM reservation objects
Date: Thu, 27 Aug 2026 13:11:42 +0000	[thread overview]
Message-ID: <20260827131142.C43BB1F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260827124910.2245-9-christian.koenig@amd.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Double allocation of `dma_resv` causes a permanent memory leak because `vm->_resv` is allocated twice and the first pointer is unconditionally overwritten.
- [High] Calls to `i915_address_space_init()` ignore the new `-ENOMEM` error return value, leading to incomplete initialization and potential NULL pointer dereferences.
--

commit 5239b0e3c5a536da51a7fa10affcf28e378bea31
Author: Christian König <ckoenig.leichtzumerken@gmail.com>
drm/i915/gt: Use dma_resv_alloc for VM reservation objects

Replaces the embedded dma_resv object in struct i915_address_space with a
dynamically allocated pointer, returning int from initialization functions
to properly handle allocation failures.

> diff --git a/drivers/gpu/drm/i915/gt/intel_gtt.c b/drivers/gpu/drm/i915/gt/intel_gtt.c
> index 7b1bdb121c88d..670cbe0b8cc05 100644
> --- a/drivers/gpu/drm/i915/gt/intel_gtt.c
> +++ b/drivers/gpu/drm/i915/gt/intel_gtt.c
> @@ -258,7 +258,7 @@ void i915_vm_release(struct kref *kref)
>  	queue_work(vm->i915->wq, &vm->release_work);
>  }
>  
> -void i915_address_space_init(struct i915_address_space *vm, int subclass)
> +int i915_address_space_init(struct i915_address_space *vm, int subclass)
>  {

[Severity: High]
Does this change leave some callers unhandled? i915_address_space_init() now
returns an error code, but it appears some existing callers were not updated
to check the return value. 

For instance, i915_dpt_create() in drivers/gpu/drm/i915/i915_dpt.c, as well
as the mock tests in drivers/gpu/drm/i915/selftests/mock_gtt.c, seem to ignore
this return value. If dma_resv_alloc() fails under memory pressure, it could
leave vm->mm uninitialized and vm->_resv as NULL, which might lead to a panic
later when the Display Page Table is used.

[ ... ]

> @@ -295,7 +295,10 @@ void i915_address_space_init(struct i915_address_space *vm, int subclass)
>  		might_alloc(GFP_KERNEL);
>  		mutex_release(&vm->mutex.dep_map, _THIS_IP_);
>  	}
> -	dma_resv_init(&vm->_resv);
> +
> +	vm->_resv = dma_resv_alloc();
> +	if (!vm->_resv)
> +		return -ENOMEM;

[Severity: High]
Could this unconditionally overwrite an already allocated vm->_resv pointer?

The callers ppgtt_init() and ggtt_probe_hw() explicitly allocate vm->_resv
before calling i915_address_space_init(), which then allocates it again here.
This appears to cause a permanent memory leak of the first allocation on every
successful VM initialization.

>  
>  	GEM_BUG_ON(!vm->total);

[ ... ]

> diff --git a/drivers/gpu/drm/i915/gt/intel_ppgtt.c b/drivers/gpu/drm/i915/gt/intel_ppgtt.c
> index 72d8473a448b9..9abd4faa2e550 100644
> --- a/drivers/gpu/drm/i915/gt/intel_ppgtt.c
> +++ b/drivers/gpu/drm/i915/gt/intel_ppgtt.c
> @@ -315,9 +315,17 @@ void ppgtt_init(struct i915_ppgtt *ppgtt, struct intel_gt *gt,
>  	ppgtt->vm.total = BIT_ULL(RUNTIME_INFO(i915)->ppgtt_size);
>  	ppgtt->vm.lmem_pt_obj_flags = lmem_pt_obj_flags;
>  
> -	dma_resv_init(&ppgtt->vm._resv);
> -	i915_address_space_init(&ppgtt->vm, VM_CLASS_PPGTT);
> +	ppgtt->vm._resv = dma_resv_alloc();
> +	if (!ppgtt->vm._resv)
> +		return -ENOMEM;
> +
> +	if (i915_address_space_init(&ppgtt->vm, VM_CLASS_PPGTT)) {
> +		dma_resv_put(ppgtt->vm._resv);
> +		return -ENOMEM;
> +	}

[Severity: High]
If i915_address_space_init() fails, does this leak the first allocation?

Inside i915_address_space_init(), if its own dma_resv_alloc() fails,
ppgtt->vm._resv is clobbered to NULL. When control returns here and
dma_resv_put() is called, it will be passing NULL, leaving the original
allocation leaked.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260827124910.2245-1-christian.koenig@amd.com?part=8

  reply	other threads:[~2026-08-27 13:11 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-27 12:38 Refcounting dma_resv v2 Christian König
2026-08-27 12:38 ` [PATCH 01/10] dma-buf: Add reference counting to dma_resv Christian König
2026-08-27 18:39   ` Andi Shyti
2026-08-28 18:21   ` Danilo Krummrich
2026-08-28 19:17     ` Matthew Brost
2026-08-28 19:34       ` Matthew Brost
2026-08-31  7:37         ` Christian König
2026-08-31 21:09           ` Matthew Brost
2026-08-31  7:31     ` Christian König
2026-08-27 12:38 ` [PATCH 02/10] dma-buf/tests: Convert st-dma-resv tests to use dma_resv_alloc Christian König
2026-08-27 13:08   ` sashiko-bot
2026-08-27 12:38 ` [PATCH 03/10] drm/gem: Add helper for drm_gem_object resv assignment Christian König
2026-08-27 13:22   ` sashiko-bot
2026-08-27 12:38 ` [PATCH 04/10] drm/gem: Convert drm_gem_private_object_init to return error code Christian König
2026-08-27 13:19   ` sashiko-bot
2026-08-31 20:59   ` Youssef Samir
2026-08-27 12:38 ` [PATCH 05/10] drm/gem: Use dynamic allocation for GEM object dma_resv Christian König
2026-08-27 13:13   ` sashiko-bot
2026-08-27 12:38 ` [PATCH 06/10] drm/mode_config: Use dma_resv_alloc for lockdep annotation Christian König
2026-08-27 13:02   ` sashiko-bot
2026-08-27 12:38 ` [PATCH 07/10] drm/xe: " Christian König
2026-08-27 13:04   ` sashiko-bot
2026-08-27 12:38 ` [PATCH 08/10] drm/i915/gt: Use dma_resv_alloc for VM reservation objects Christian König
2026-08-27 13:11   ` sashiko-bot [this message]
2026-08-27 12:38 ` [PATCH 09/10] drm/ttm/tests: Use dma_resv_alloc in test files Christian König
2026-08-27 13:12   ` sashiko-bot
2026-08-27 12:38 ` [PATCH 10/10] dma-buf: Inline dma_resv_init and remove allocated flag Christian König
2026-08-27 13:31   ` sashiko-bot
2026-08-27 13:39 ` ✗ Fi.CI.BUILD: failure for series starting with [01/10] dma-buf: Add reference counting to dma_resv Patchwork

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=20260827131142.C43BB1F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=ckoenig.leichtzumerken@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=intel-gfx@lists.freedesktop.org \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.