Re: [PATCH 0/2] mm: memory-failure: fix HWPoison flag race with non-atomic page flag ops
From: Andi Kleen
Date: Sun Jun 28 2026 - 22:21:45 EST
On Sun, Jun 28, 2026 at 05:45:22PM -0400, Michael S. Tsirkin wrote:
> This series fixes the race by:
>
> 1. Having memory_failure() call synchronize_rcu() + retry after
> setting HWPoison, so that any in-flight non-atomic RMW that
> read the old flags value completes before we proceed.
>
> 2. Wrapping all non-atomic page flag operations in
> rcu_read_lock/rcu_read_unlock (CONFIG_MEMORY_FAILURE only),
> so that synchronize_rcu() actually drains them.
It wouldn't surprise me if your underlying performance assumptions
-- an non contended atomic is cheaper than a rcu_read_lock/unlock --
are not true in various CPU/kernel configuration combinations.
Modern CPUs have fast atomics when uncontended in normal circumstances.
But it probably doesn't matter much either way because the difference
shouldn't be very much. It seems very complicated for something that
could be much simpler.
But I guess it's fine.
-Andi
>
> Performance impact (page alloc+free microbenchmark, 200K iterations,
> 20 runs, KVM guest, error bars are 3-sigma):
>
> !PREEMPT_RCU (x86):
> insns/iter cycles/iter
> base: 12237 +/- 1 17954 +/- 136
> patched: +22 +/- 1 -124 +/- 122
> (+0.18%) (within noise)
>
> PREEMPT_RCU:
> insns/iter cycles/iter
> base: 12512 +/- 3 18541 +/- 214
> patched: +95 +/- 3 -12 +/- 161
> (+0.76%) (within noise)
>
> When !CONFIG_MEMORY_FAILURE, all wrappers compile away completely.