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*... ?