Re: [PATCH v2 2/4] ptp: vmclock: support device notifications

From
David Woodhouse <dwmw2@infradead.org>
Date
2025-12-02 23:45:37
Also in
lkml
Reply to
Chalios, Babis, 2025-12-02
On Tue, 2025-12-02 at 20:11 +0000, Chalios, Babis wrote:
quoted hunk ↗ jump to hunk
@@ -402,8 +413,16 @@ static ssize_t vmclock_miscdev_read(struct file *fp, char __user *buf,
 
 		/* Pairs with hypervisor wmb */
 		virt_rmb();
-		if (seq == le32_to_cpu(st->clk->seq_count))
-			break;
+		if (seq == le32_to_cpu(st->clk->seq_count)) {
+			/*
+			 * Either we updated fst->seq to seq (the latest version we observed)
+			 * or someone else did (old_seq == seq), so we can break.
+			 */
+			if (atomic_try_cmpxchg(&fst->seq, &old_seq, seq) ||
+			    old_seq == seq) {
+				break;
+			}
+		}
 
 		if (ktime_after(ktime_get(), deadline))
 			return -ETIMEDOUT;
I'm slightly confused that that compiles cleanly (as it does here).
Isn't the second argument to atomic_try_cmpxchg() an (int *), and isn't
old_seq a uint32_t? It's doing the right thing; I just didn't think it
would do the right thing *quietly*... ?

Attachments

Thread (10 messages) 10 messages, 3 authors, last reply 2025-12-03
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help