RDMAVT: Fix synchronization around percpu_ref
authorTejun Heo <tj@kernel.org>
Wed, 14 Mar 2018 19:10:18 +0000 (12:10 -0700)
committerTejun Heo <tj@kernel.org>
Wed, 14 Mar 2018 19:10:18 +0000 (12:10 -0700)
commit74b44bbe80b4c62113ac1501482ea1ee40eb9d67
treebeed7a8028f6f71ba59cfb38074bea91a067bd41
parentd0264c01e7587001a8c4608a5d1818dba9a4c11a
RDMAVT: Fix synchronization around percpu_ref

rvt_mregion uses percpu_ref for reference counting and RCU to protect
accesses from lkey_table.  When a rvt_mregion needs to be freed, it
first gets unregistered from lkey_table and then rvt_check_refs() is
called to wait for in-flight usages before the rvt_mregion is freed.

rvt_check_refs() seems to have a couple issues.

* It has a fast exit path which tests percpu_ref_is_zero().  However,
  a percpu_ref reading zero doesn't mean that the object can be
  released.  In fact, the ->release() callback might not even have
  started executing yet.  Proceeding with freeing can lead to
  use-after-free.

* lkey_table is RCU protected but there is no RCU grace period in the
  free path.  percpu_ref uses RCU internally but it's sched-RCU whose
  grace periods are different from regular RCU.  Also, it generally
  isn't a good idea to depend on internal behaviors like this.

To address the above issues, this patch removes the fast exit and adds
an explicit synchronize_rcu().

Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Dennis Dalessandro <dennis.dalessandro@intel.com>
Cc: Mike Marciniszyn <mike.marciniszyn@intel.com>
Cc: linux-rdma@vger.kernel.org
Cc: Linus Torvalds <torvalds@linux-foundation.org>
drivers/infiniband/sw/rdmavt/mr.c