migration: fix ineffective overflow assert in postcopy blocktime
vcpu_faults_current[] is uint8_t. The overflow assert was checked after the post-increment, so 255 would wrap to 0 and the assert would pass silently. Move the check before the increment and use < 255. Signed-off-by: Bin Guo <guobin@linux.alibaba.com> Link: https://lore.kernel.org/r/20260716101952.65329-2-guobin@linux.alibaba.com Signed-off-by: Peter Xu <peterx@redhat.com>
Bin Guo committed
Jul 16, 2026 at 18:19 UTC
c923ae77e70abda40d786e7a367517a61969235b
1 file changed
+4
-3
migration/postcopy-ram.c
+4
-3
@@ -1093,7 +1093,11 @@ void mark_postcopy_blocktime_begin(uintptr_t addr, uint32_t ptid,
1093
/*
1094
* Account how many concurrent faults on this vCPU we trapped. See
1095
* comments above vcpu_faults_current[] on why it can be more than one.
1096
+ *
1097
+ * vcpu_faults_current[] is uint8_t, so assert before incrementing to
1098
+ * catch overflow before it wraps.
1099
*/
1100
+ assert(dc->vcpu_faults_current[cpu] < 255);
1101
if (dc->vcpu_faults_current[cpu]++ == 0) {
1102
dc->smp_cpus_down++;
1103
/*
@@ -1103,9 +1107,6 @@ void mark_postcopy_blocktime_begin(uintptr_t addr, uint32_t ptid,
1107
*/
1108
dc->last_begin = current;
1109
}
1106
-
1107
- /* Making sure it won't overflow - it really should never! */
1108
- assert(dc->vcpu_faults_current[cpu] <= 255);
1110
} else {
1111
/*
1112
* For non-vCPU thread faults, we don't care about tid or cpu index