From: Deepak R Varma <drv@mailo.com>
To: Matthew Auld <matthew.auld@intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>,
Jani Nikula <jani.nikula@linux.intel.com>,
Joonas Lahtinen <joonas.lahtinen@linux.intel.com>,
Rodrigo Vivi <rodrigo.vivi@intel.com>,
David Airlie <airlied@gmail.com>, Daniel Vetter <daniel@ffwll.ch>,
intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
linux-kernel@vger.kernel.org,
Thomas Hellstrom <thomas.hellstrom@intel.com>,
Saurabh Singh Sengar <ssengar@microsoft.com>,
Praveen Kumar <kumarpraveen@linux.microsoft.com>,
Deepak R Varma <drv@mailo.com>
Subject: Re: [PATCH] drm/i915/gt: Avoid redundant pointer validity check
Date: Tue, 7 Feb 2023 00:12:18 +0530 [thread overview]
Message-ID: <Y+FKCth+0r/757Xu@ubun2204.myguest.virtualbox.org> (raw)
In-Reply-To: <aa8af778-2a40-7fe0-eb14-234469c74523@intel.com>
On Mon, Feb 06, 2023 at 10:33:13AM +0000, Matthew Auld wrote:
> On 06/02/2023 09:45, Tvrtko Ursulin wrote:
> >
> > Hi,
> >
> > Adding Matt & Thomas as potential candidates to review.
> >
> > Regards,
> >
> > Tvrtko
> >
> > On 03/02/2023 19:30, Deepak R Varma wrote:
> > > The macro definition of gen6_for_all_pdes() expands to a for loop such
> > > that it breaks when the page table is null. Hence there is no need to
> > > again test validity of the page table entry pointers in the pde list.
> > > This change is identified using itnull.cocci semantic patch.
> > >
> > > Signed-off-by: Deepak R Varma <drv@mailo.com>
> > > ---
> > > Please note: Proposed change is compile tested only.
> > >
> > > drivers/gpu/drm/i915/gt/gen6_ppgtt.c | 5 ++---
> > > 1 file changed, 2 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/drivers/gpu/drm/i915/gt/gen6_ppgtt.c
> > > b/drivers/gpu/drm/i915/gt/gen6_ppgtt.c
> > > index 5aaacc53fa4c..787b9e6d9f59 100644
> > > --- a/drivers/gpu/drm/i915/gt/gen6_ppgtt.c
> > > +++ b/drivers/gpu/drm/i915/gt/gen6_ppgtt.c
> > > @@ -258,8 +258,7 @@ static void gen6_ppgtt_free_pd(struct gen6_ppgtt
> > > *ppgtt)
> > > u32 pde;
> > > gen6_for_all_pdes(pt, pd, pde)
> > > - if (pt)
> > > - free_pt(&ppgtt->base.vm, pt);
> > > + free_pt(&ppgtt->base.vm, pt);
> > > }
> > > static void gen6_ppgtt_cleanup(struct i915_address_space *vm)
> > > @@ -304,7 +303,7 @@ static void pd_vma_unbind(struct
> > > i915_address_space *vm,
> > > /* Free all no longer used page tables */
> > > gen6_for_all_pdes(pt, ppgtt->base.pd, pde) {
> > > - if (!pt || atomic_read(&pt->used))
> > > + if (atomic_read(&pt->used))
>
> Wow, I was really confused trying to remember how this all works.
>
> The gen6_for_all_pdes() does:
>
> (pt = i915_pt_entry(pd, iter), true)
>
> So NULL pt is expected, and does not 'break' here, since 'true' is always
> the value that decides whether to terminate the loop. So this patch would
> lead to NULL ptr deref, AFAICT.
Hello Matt,
I understand it now. I was misreading the true as part of the function argument.
Could you please also comment if the implementation of gen6_ppgtt_free_pd() in
the same file is safe? It doesn't appear to have an check on pt validity here.
Thank you,
deepak.
>
>
>
> > > continue;
> > > free_pt(&ppgtt->base.vm, pt);
next prev parent reply other threads:[~2023-02-06 18:42 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-03 19:30 Deepak R Varma
2023-02-06 9:45 ` Tvrtko Ursulin
2023-02-06 10:33 ` Matthew Auld
2023-02-06 18:42 ` Deepak R Varma [this message]
2023-02-06 18:53 ` Deepak R Varma
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=Y+FKCth+0r/757Xu@ubun2204.myguest.virtualbox.org \
--to=drv@mailo.com \
--cc=airlied@gmail.com \
--cc=daniel@ffwll.ch \
--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=kumarpraveen@linux.microsoft.com \
--cc=linux-kernel@vger.kernel.org \
--cc=matthew.auld@intel.com \
--cc=rodrigo.vivi@intel.com \
--cc=ssengar@microsoft.com \
--cc=thomas.hellstrom@intel.com \
--cc=tvrtko.ursulin@linux.intel.com \
/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
all inboxes | Powered by JetHome®