Re: [RFC 1/8] mm: add overflow and underflow checks for page->_refcount

From: Muchun Song
Date: Wed Oct 27 2021 - 03:47:25 EST


On Wed, Oct 27, 2021 at 1:38 AM Pasha Tatashin
<pasha.tatashin@xxxxxxxxxx> wrote:
>
> The problems with page->_refcount are hard to debug, because usually
> when they are detected, the damage has occurred a long time ago. Yet,
> the problems with invalid page refcount may be catastrophic and lead to
> memory corruptions.
>
> Reduce the scope of when the _refcount problems manifest themselves by
> adding checks for underflows and overflows into functions that modify
> _refcount.
>
> Signed-off-by: Pasha Tatashin <pasha.tatashin@xxxxxxxxxx>

I found some atomic_add/dec are replaced with atomic_add/dec_return,
those helpers with return value imply a full memory barrier around it, but
others without return value do not. Do you have any numbers to show
the impact? Maybe atomic_add/dec_return_relaxed can help this.

Thanks.