All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Thomas Hellström" <thomas.hellstrom@linux.intel.com>
To: Dan Carpenter <dan.carpenter@linaro.org>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [bug report] drm/ttm, drm_xe, Implement ttm_lru_walk_for_evict() using the guarded LRU iteration
Date: Mon, 21 Jul 2025 16:35:49 +0200	[thread overview]
Message-ID: <104f9c315544db102c933e82f6a02836e2033b64.camel@linux.intel.com> (raw)
In-Reply-To: <cc9453cb-6f6e-4122-aa17-3fdf8af312e0@sabinyo.mountain>

On Sat, 2025-06-28 at 22:51 -0500, Dan Carpenter wrote:
> Hello Thomas Hellström,
> 
> Commit bb8aa27eff6f ("drm/ttm, drm_xe, Implement
> ttm_lru_walk_for_evict() using the guarded LRU iteration") from Jun
> 23, 2025 (linux-next), leads to the following (unpublished) Smatch
> static checker warning:
> 
> 	drivers/gpu/drm/ttm/ttm_bo_util.c:991
> __ttm_bo_lru_cursor_next()
> 	warn: duplicate check 'res' (previous on line 952)
> 
> drivers/gpu/drm/ttm/ttm_bo_util.c
>    931  __ttm_bo_lru_cursor_next(struct ttm_bo_lru_cursor *curs)
>    932  {
>    933          spinlock_t *lru_lock = &curs->res_curs.man->bdev-
> >lru_lock;
>    934          struct ttm_resource *res = NULL;
>    935          struct ttm_buffer_object *bo;
>    936          struct ttm_lru_walk_arg *arg = curs->arg;
>    937          bool first = !curs->bo;
>    938  
>    939          ttm_bo_lru_cursor_cleanup_bo(curs);
>    940  
>    941          spin_lock(lru_lock);
>    942          for (;;) {
>    943                  int mem_type, ret = 0;
>    944                  bool bo_locked = false;
>    945  
>    946                  if (first) {
>    947                          res =
> ttm_resource_manager_first(&curs->res_curs);
>    948                          first = false;
>    949                  } else {
>    950                          res =
> ttm_resource_manager_next(&curs->res_curs);
>    951                  }
>    952                  if (!res)
>    953                          break;
> 
> This is the only break statement
> 
>    954  
>    955                  bo = res->bo;
>    956                  if (ttm_lru_walk_trylock(curs, bo))
>    957                          bo_locked = true;
>    958                  else if (!arg->ticket || arg->ctx-
> >no_wait_gpu || arg->trylock_only)
>    959                          continue;
>    960  
>    961                  if (!ttm_bo_get_unless_zero(bo)) {
>    962                          if (curs->needs_unlock)
>    963                                  dma_resv_unlock(bo-
> >base.resv);
>    964                          continue;
>    965                  }
>    966  
>    967                  mem_type = res->mem_type;
>    968                  spin_unlock(lru_lock);
>    969                  if (!bo_locked)
>    970                          ret = ttm_lru_walk_ticketlock(curs,
> bo);
>    971  
>    972                  /*
>    973                   * Note that in between the release of the
> lru lock and the
>    974                   * ticketlock, the bo may have switched
> resource,
>    975                   * and also memory type, since the resource
> may have been
>    976                   * freed and allocated again with a different
> memory type.
>    977                   * In that case, just skip it.
>    978                   */
>    979                  curs->bo = bo;
>    980                  if (!ret && bo->resource && bo->resource-
> >mem_type == mem_type)
>    981                          return bo;
>    982  
>    983                  ttm_bo_lru_cursor_cleanup_bo(curs);
>    984                  if (ret && ret != -EALREADY)
>    985                          return ERR_PTR(ret);
>    986  
>    987                  spin_lock(lru_lock);
>    988          }
>    989  
>    990          spin_unlock(lru_lock);
>    991          return res ? bo : NULL;
> 
> So we know res is NULL and we could just change this to "return
> NULL;"

Right.
Thanks for the report. Will put together a patch.

Thanks,
Thomas


> 
>    992  }
> 
> regards,
> dan carpenter


  reply	other threads:[~2025-07-21 14:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-29  3:51 [bug report] drm/ttm, drm_xe, Implement ttm_lru_walk_for_evict() using the guarded LRU iteration Dan Carpenter
2025-07-21 14:35 ` Thomas Hellström [this message]
  -- strict thread matches above, loose matches on Subject: below --
2025-07-01 17:49 Dan Carpenter
2025-07-21 14:10 ` Thomas Hellström

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=104f9c315544db102c933e82f6a02836e2033b64.camel@linux.intel.com \
    --to=thomas.hellstrom@linux.intel.com \
    --cc=dan.carpenter@linaro.org \
    --cc=dri-devel@lists.freedesktop.org \
    /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.