Skip to contentSkip to conversation

libceph: Avoid unsequenced accesses to jiffies in dump_linger_request()

PATCH In review Nathan Chancellor 2 participants 2 messages Nov 15 – Nov 16 Ceph common code (libceph)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libceph: Avoid unsequenced accesses to jiffies in dump_linger_request()

After a recent improvement in clang to warn on unsequenced accesses to volatile variables [1], an instance appear in dump_linger_request(), which can break the build with CONFIG_WERROR=y / W=e:

net/ceph/debugfs.c:269:42: error: unsequenced accesses to volatile qualified 'jiffies' [-Werror,-Wunsequenced]

    267 |                    req ? jiffies_to_msecs(jiffies - req->r_start_stamp) : 0,
        |                                           ~~~~~~~
    268 |                    lreq->is_watch && lreq->committed && !lreq->last_error ?
    269 |                         jiffies_to_msecs(jiffies - lreq->watch_valid_thru) : 0,
        |                                          ^

Per C11 5.1.2.3.2, accessing a volatile object is a side effect. Per C11 6.5.2, unsequenced side effects on the same scalar object are undefined behavior. Per C11 6.5.2.2.10/12, the evaluation of arguments in a function call is indeterminately sequenced, meaning any side effects in the arguments are unsequenced.

Add a local variable to hold the value of jiffies before the function call so that there are no unsequenced side effects, clearing up the warning.

---
 net/ceph/debugfs.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
net/ceph/debugfs.c +3 -2
index b068e25f2acc..82270f0e4d7e 100644
@@ -259,14 +259,15 @@ static void dump_linger_request(struct seq_file *s,
 	struct ceph_osd_request *req =
 	    list_first_entry_or_null(&lreq->osd_reqs, struct ceph_osd_request,
 				     r_private_item);
+	unsigned long j = jiffies;
 
 	seq_printf(s, "%llu\t", lreq->linger_id);
 	dump_target(s, &lreq->t);
 
 	seq_printf(s, "\t%u\t%u\t%u\t%s%s/%d\n", lreq->register_gen,
-		   req ? jiffies_to_msecs(jiffies - req->r_start_stamp) : 0,
+		   req ? jiffies_to_msecs(j - req->r_start_stamp) : 0,
 		   lreq->is_watch && lreq->committed && !lreq->last_error ?
-                        jiffies_to_msecs(jiffies - lreq->watch_valid_thru) : 0,
+                        jiffies_to_msecs(j - lreq->watch_valid_thru) : 0,
 		   lreq->is_watch ? "W" : "N", lreq->committed ? "C" : "",
 		   lreq->last_error);
 }

---
base-commit: a407f99619029b76548774af1006319f810bb345
base-tree: git://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git master
change-id: 20261115-ceph-wunsequenced-44a2019df3ff

Best regards,

Signature · 2 lines
Cheers,
Nathan