Re: [PATCH] mm/vmscan: fix data races at kswapd_classzone_idx

From: Matthew Wilcox
Date: Tue Feb 25 2020 - 20:30:19 EST


On Tue, Feb 25, 2020 at 11:55:26AM -0500, Qian Cai wrote:
> - if (pgdat->kswapd_classzone_idx == MAX_NR_ZONES)
> - pgdat->kswapd_classzone_idx = classzone_idx;
> - else
> - pgdat->kswapd_classzone_idx = max(pgdat->kswapd_classzone_idx,
> - classzone_idx);
> + if (READ_ONCE(pgdat->kswapd_classzone_idx) == MAX_NR_ZONES ||
> + READ_ONCE(pgdat->kswapd_classzone_idx) < classzone_idx)
> + WRITE_ONCE(pgdat->kswapd_classzone_idx, classzone_idx);
> +
> pgdat->kswapd_order = max(pgdat->kswapd_order, order);

Doesn't this line have the exact same problem you're "solving" above?

Also, why would you do this crazy "f(READ_ONCE(x)) || g(READ_ONCE(x))?
Surely you should be stashing READ_ONCE(x) into a local variable?

And there are a _lot_ of places which access kswapd_classzone_idx
without a lock. Are you sure this patch is sufficient?