]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
srcu: Use rcu_seq_done_exact() for polling API
authorJoel Fernandes <joelagnelf@nvidia.com>
Thu, 13 Feb 2025 16:47:27 +0000 (11:47 -0500)
committerJoel Fernandes <joelagnelf@nvidia.com>
Tue, 8 Apr 2025 18:55:55 +0000 (14:55 -0400)
poll_state_synchronize_srcu() uses rcu_seq_done() unlike
poll_state_synchronize_rcu() which uses rcu_seq_done_exact().

The  rcu_seq_done_exact() makes more sense for polling API, as with
this API, there is a higher chance that there is a significant delay
between the get_state..() and poll_state..() calls since a cookie
can be stored and reused at a later time. During such a delay, if
the gp_seq counter progresses more than ULONG_MAX/2 distance, then
poll_state..() may return false for a long time unwantedly.

Fix by using the more accurate rcu_seq_done_exact() API which is
exactly what straight RCU's polling does.

It may make sense, as future work, to add debug code here as well, where
we compare a physical timestamp between get_state..() and poll_state()
calls and yell if significant time has past but the grace period has
still not progressed.

Reviewed-by: Neeraj Upadhyay <Neeraj.Upadhyay@amd.com>
Reviewed-by: Paul E. McKenney <paulmck@kernel.org>
Reviewed-by: Kent Overstreet <kent.overstreet@linux.dev>
Cc: Kent Overstreet <kent.overstreet@linux.dev>
Signed-off-by: Joel Fernandes <joelagnelf@nvidia.com>
kernel/rcu/srcutree.c

index 9a59b071501bd8715dbb99c317818d1f796a51c3..48047260697ecff12cca5641f7e5d509f9ad04a8 100644 (file)
@@ -1589,7 +1589,7 @@ EXPORT_SYMBOL_GPL(start_poll_synchronize_srcu);
 bool poll_state_synchronize_srcu(struct srcu_struct *ssp, unsigned long cookie)
 {
        if (cookie != SRCU_GET_STATE_COMPLETED &&
-           !rcu_seq_done(&ssp->srcu_sup->srcu_gp_seq, cookie))
+           !rcu_seq_done_exact(&ssp->srcu_sup->srcu_gp_seq, cookie))
                return false;
        // Ensure that the end of the SRCU grace period happens before
        // any subsequent code that the caller might execute.