From: "Ville Syrjälä" <ville.syrjala@linux.intel.com>
To: Chengyu Liu <lui2012qwq@gmail.com>
Cc: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
jani.nikula@linux.intel.com, joonas.lahtinen@linux.intel.com,
rodrigo.vivi@intel.com, tursulin@ursulin.net,
stable@vger.kernel.org
Subject: Re: [PATCH 1/2] i915/gt: tolerate ERR_PTR pd in gen6_ppgtt teardown
Date: Wed, 4 Nov 2026 17:18:05 +0200 [thread overview]
Message-ID: <autMrRaeVWRtBlMP@intel.com> (raw)
In-Reply-To: <20261104073311.1617823-2-lui2012qwq@gmail.com>
On Wed, Nov 04, 2026 at 03:33:10PM +0800, Chengyu Liu wrote:
> gen6_ppgtt_create() stores the result of gen6_alloc_top_pd() into
> ppgtt->base.pd and, on failure, jumps to err_put with the ERR_PTR still
> in the field. i915_vm_put() runs vm->cleanup = gen6_ppgtt_cleanup(),
> which calls gen6_ppgtt_free_pd(), where gen6_for_all_pdes() immediately
> dereferences pd - with an ERR_PTR that is an invalid dereference and a
> crash (in the async release worker). The free_pd() right after is only
> guarded against NULL, not ERR_PTR.
>
> Bail out of gen6_ppgtt_free_pd() for an invalid pd and skip free_pd()
> likewise, so an allocation failure under memory pressure stays a plain
> -ENOMEM instead of an oops.
The correct fix would be to not assign the error pointer
into ppgtt->base.pd in the first place.
Looks like a somwhat common bad pattern in this code that
received pointers are assigned directly into their final
location, and if the pointer is an error then the pointer is
cleared. IMO one should never do that because it's very easy
to forget the clearing part. Instead one should always use
local variable first, and only assign the final pointer after
having checked that the pointer is valid.
>
> Found by static analysis.
>
> Cc: stable@vger.kernel.org
> Signed-off-by: Chengyu Liu <lui2012qwq@gmail.com>
> ---
> drivers/gpu/drm/i915/gt/gen6_ppgtt.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/i915/gt/gen6_ppgtt.c b/drivers/gpu/drm/i915/gt/gen6_ppgtt.c
> index 438cd4724a..72a9ad4642 100644
> --- a/drivers/gpu/drm/i915/gt/gen6_ppgtt.c
> +++ b/drivers/gpu/drm/i915/gt/gen6_ppgtt.c
> @@ -259,6 +259,9 @@ static void gen6_ppgtt_free_pd(struct gen6_ppgtt *ppgtt)
> struct i915_page_table *pt;
> u32 pde;
>
> + if (IS_ERR_OR_NULL(pd))
> + return;
> +
> gen6_for_all_pdes(pt, pd, pde)
> if (pt)
> free_pt(&ppgtt->base.vm, pt);
> @@ -271,7 +274,7 @@ static void gen6_ppgtt_cleanup(struct i915_address_space *vm)
> gen6_ppgtt_free_pd(ppgtt);
> free_scratch(vm);
>
> - if (ppgtt->base.pd)
> + if (!IS_ERR_OR_NULL(ppgtt->base.pd))
> free_pd(&ppgtt->base.vm, ppgtt->base.pd);
>
> mutex_destroy(&ppgtt->flush);
> --
> 2.25.1
--
Ville Syrjälä
Intel
next prev parent reply other threads:[~2026-11-04 15:18 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-04 7:33 [PATCH 0/2] i915: two teardown fixes (gen6 ppgtt ERR_PTR, OA config sysfs leak) Chengyu Liu
2026-11-04 7:33 ` [PATCH 1/2] i915/gt: tolerate ERR_PTR pd in gen6_ppgtt teardown Chengyu Liu
2026-11-04 15:18 ` Ville Syrjälä [this message]
2026-11-05 6:04 ` Chengyu Liu
2026-11-04 7:33 ` [PATCH 2/2] i915/perf: remove sysfs entry if idr_alloc() fails in add_config Chengyu Liu
2026-11-04 21:42 ` ✗ LGCI.VerificationFailed: failure for i915: two teardown fixes (gen6 ppgtt ERR_PTR, OA config sysfs leak) Patchwork
2026-11-05 4:09 ` ✓ i915.CI.BAT: success for i915: two teardown fixes (gen6 ppgtt ERR_PTR, OA config sysfs leak) (rev2) Patchwork
2026-11-05 6:41 ` ✓ i915.CI.Full: " 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=autMrRaeVWRtBlMP@intel.com \
--to=ville.syrjala@linux.intel.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=jani.nikula@linux.intel.com \
--cc=joonas.lahtinen@linux.intel.com \
--cc=lui2012qwq@gmail.com \
--cc=rodrigo.vivi@intel.com \
--cc=stable@vger.kernel.org \
--cc=tursulin@ursulin.net \
/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.