OSDN Git Service

drm/mm: Use clear_bit_unlock() for releasing the drm_mm_node()
authorChris Wilson <chris@chris-wilson.co.uk>
Thu, 3 Oct 2019 21:01:00 +0000 (22:01 +0100)
committerChris Wilson <chris@chris-wilson.co.uk>
Fri, 4 Oct 2019 12:43:43 +0000 (13:43 +0100)
commit3dda22d3dcd1fc39e7867b2c5f5fc8fa79fdefcc
treef7074121eac9203209c3de91008807438b44719f
parent4ee92c7149da9cb1991684628a9e47166a5e26f6
drm/mm: Use clear_bit_unlock() for releasing the drm_mm_node()

A few callers need to serialise the destruction of their drm_mm_node and
ensure it is removed from the drm_mm before freeing. However, to be
completely sure that any access from another thread is complete before
we free the struct, we require the RELEASE semantics of
clear_bit_unlock().

This allows the conditional locking such as

Thread A Thread B
  mutex_lock(mm_lock);   if (drm_mm_node_allocated(node)) {
  drm_mm_node_remove(node);     mutex_lock(mm_lock);
  mutex_unlock(mm_lock);     if (drm_mm_node_allocated(node))
      drm_mm_node_remove(node);
    mutex_unlock(mm_lock);
  }
  kfree(node);

to serialise correctly without any lingering accesses from A to the
freed node. Allocation / insertion of the node is assumed never to race
with removal or eviction scanning.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20191003210100.22250-5-chris@chris-wilson.co.uk
drivers/gpu/drm/drm_mm.c