mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Nathan Chancellor <nathan@kernel.org>
To: Ilya Dryomov <idryomov@gmail.com>,
	Alex Markuze <amarkuze@redhat.com>,
	 Xiubo Li <xiubo.li@clyso.com>
Cc: Viacheslav Dubeyko <slava@dubeyko.com>,
	ceph-devel@vger.kernel.org,  linux-kernel@vger.kernel.org,
	llvm@lists.linux.dev,  Nathan Chancellor <nathan@kernel.org>
Subject: [PATCH] libceph: Avoid unsequenced accesses to jiffies in dump_linger_request()
Date: Sun, 15 Nov 2026 14:39:13 -0700	[thread overview]
Message-ID: <20261115-ceph-wunsequenced-v1-1-6910c560ba9b@kernel.org> (raw)

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.

Fixes: a407f9961902 ("libceph: include current latency in debugfs osdc dump")
Closes: https://github.com/ClangBuiltLinux/linux/issues/2200
Link: https://github.com/llvm/llvm-project/commit/955715460eaf9188c241c74750637fc82dfcc423 [1]
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
 net/ceph/debugfs.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/net/ceph/debugfs.c b/net/ceph/debugfs.c
index b068e25f2acc..82270f0e4d7e 100644
--- a/net/ceph/debugfs.c
+++ b/net/ceph/debugfs.c
@@ -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,
--  
Cheers,
Nathan


                 reply	other threads:[~2026-11-15 21:39 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261115-ceph-wunsequenced-v1-1-6910c560ba9b@kernel.org \
    --to=nathan@kernel.org \
    --cc=amarkuze@redhat.com \
    --cc=ceph-devel@vger.kernel.org \
    --cc=idryomov@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=slava@dubeyko.com \
    --cc=xiubo.li@clyso.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®