Commit e623a48e authored by Håkon Bugge's avatar Håkon Bugge Committed by David S. Miller

rds: Make sure updates to cp_send_gen can be observed

cp->cp_send_gen is treated as a normal variable, although it may be
used by different threads.

This is fixed by using {READ,WRITE}_ONCE when it is incremented and
READ_ONCE when it is read outside the {acquire,release}_in_xmit
protection.

Normative reference from the Linux-Kernel Memory Model:

    Loads from and stores to shared (but non-atomic) variables should
    be protected with the READ_ONCE(), WRITE_ONCE(), and
    ACCESS_ONCE().

Clause 5.1.2.4/25 in the C standard is also relevant.
Signed-off-by: default avatarHåkon Bugge <haakon.bugge@oracle.com>
Reviewed-by: default avatarKnut Omang <knut.omang@oracle.com>
Acked-by: default avatarSantosh Shilimkar <santosh.shilimkar@oracle.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 070f9c65
...@@ -170,8 +170,8 @@ int rds_send_xmit(struct rds_conn_path *cp) ...@@ -170,8 +170,8 @@ int rds_send_xmit(struct rds_conn_path *cp)
* The acquire_in_xmit() check above ensures that only one * The acquire_in_xmit() check above ensures that only one
* caller can increment c_send_gen at any time. * caller can increment c_send_gen at any time.
*/ */
cp->cp_send_gen++; send_gen = READ_ONCE(cp->cp_send_gen) + 1;
send_gen = cp->cp_send_gen; WRITE_ONCE(cp->cp_send_gen, send_gen);
/* /*
* rds_conn_shutdown() sets the conn state and then tests RDS_IN_XMIT, * rds_conn_shutdown() sets the conn state and then tests RDS_IN_XMIT,
...@@ -431,7 +431,7 @@ int rds_send_xmit(struct rds_conn_path *cp) ...@@ -431,7 +431,7 @@ int rds_send_xmit(struct rds_conn_path *cp)
smp_mb(); smp_mb();
if ((test_bit(0, &conn->c_map_queued) || if ((test_bit(0, &conn->c_map_queued) ||
!list_empty(&cp->cp_send_queue)) && !list_empty(&cp->cp_send_queue)) &&
send_gen == cp->cp_send_gen) { send_gen == READ_ONCE(cp->cp_send_gen)) {
rds_stats_inc(s_send_lock_queue_raced); rds_stats_inc(s_send_lock_queue_raced);
if (batch_count < send_batch_count) if (batch_count < send_batch_count)
goto restart; goto restart;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment