Skip to content

Commit e34d2d6

Browse files
Hakon-Buggejfvogel
authored andcommitted
rds: Use {READ,WRITE}_ONCE for heartbeat start and state
The heartbeat mechanism has a time-stamp and a state that are accessed from different contexts without any synchronization. Hence add proper {READ,WRITE}_ONCE(). Orabug: 30418039 Signed-off-by: Håkon Bugge <[email protected]> Reviewed-by: Ka-Cheong Poon <[email protected]> Tested-by: Michael Nowak <[email protected]> --- v1->v2: * Added Ka-Cheong's r-b * Added Mike's t-b Signed-off-by: Somasundaram Krishnasamy <[email protected]> Orabug: 30820081 UEK5 => UEK6 (cherry picked from commit 9022896) cherry-pick-repo=UEK/production/linux-uek.git Signed-off-by: Gerd Rausch <[email protected]> Reviewed-by: Sharon Liu <[email protected]>
1 parent 23e4394 commit e34d2d6

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

net/rds/recv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ rds_recv_local(struct rds_conn_path *cp, struct in6_addr *saddr,
699699
rds_send_hb(conn, 1);
700700
} else if (is_hb_pong) {
701701
rds_stats_inc(s_recv_hb_pong);
702-
cp->cp_hb_start = 0;
702+
WRITE_ONCE(cp->cp_hb_start, 0);
703703
} else {
704704
if (be16_to_cpu(inc->i_hdr.h_sport) == RDS_FLAG_PROBE_PORT)
705705
rds_stats_inc(s_recv_mprds_ping);

net/rds/threads.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ void rds_connect_path_complete(struct rds_conn_path *cp, int curr)
124124
rds_cond_queue_send_work(cp, 0);
125125
rds_clear_queued_recv_work_bit(cp);
126126
rds_cond_queue_recv_work(cp, 0);
127-
cp->cp_hb_start = 0;
128-
cp->cp_hb_state = HB_PONG_RCVD;
127+
WRITE_ONCE(cp->cp_hb_start, 0);
128+
WRITE_ONCE(cp->cp_hb_state, HB_PONG_RCVD);
129129
queue_delayed_work(cp->cp_wq, &cp->cp_hb_w, 0);
130130
cancel_delayed_work(&cp->cp_reconn_w);
131131

@@ -341,18 +341,18 @@ void rds_hb_worker(struct work_struct *work)
341341
return;
342342

343343
if (rds_conn_path_state(cp) == RDS_CONN_UP) {
344-
switch (cp->cp_hb_state) {
344+
switch (READ_ONCE(cp->cp_hb_state)) {
345345
case HB_PING_SENT:
346-
if (!cp->cp_hb_start) {
347-
cp->cp_hb_state = HB_PONG_RCVD;
346+
if (!READ_ONCE(cp->cp_hb_start)) {
347+
WRITE_ONCE(cp->cp_hb_state, HB_PONG_RCVD);
348348
/* Pseudo random from 50% to 150% of interval */
349349
delay = msecs_to_jiffies(rds_sysctl_conn_hb_interval * 1000 / 2) +
350350
msecs_to_jiffies(prandom_u32() % rds_sysctl_conn_hb_interval * 1000);
351-
} else if (now - cp->cp_hb_start > rds_sysctl_conn_hb_timeout) {
351+
} else if (now - READ_ONCE(cp->cp_hb_start) > rds_sysctl_conn_hb_timeout) {
352352
rds_rtd_ptr(RDS_RTD_CM,
353353
"RDS/IB: connection <%pI6c,%pI6c,%d> timed out (0x%lx,0x%lx)..discon and recon\n",
354354
&conn->c_laddr, &conn->c_faddr,
355-
conn->c_tos, cp->cp_hb_start, now);
355+
conn->c_tos, READ_ONCE(cp->cp_hb_start), now);
356356
rds_conn_path_drop(cp, DR_HB_TIMEOUT);
357357
return;
358358
}
@@ -367,8 +367,8 @@ void rds_hb_worker(struct work_struct *work)
367367
ret);
368368
return;
369369
}
370-
cp->cp_hb_start = now;
371-
cp->cp_hb_state = HB_PING_SENT;
370+
WRITE_ONCE(cp->cp_hb_start, now);
371+
WRITE_ONCE(cp->cp_hb_state, HB_PING_SENT);
372372
break;
373373
}
374374

0 commit comments

Comments
 (0)