linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Pasha Tatashin <pasha.tatashin@soleen.com>
To: Matthew Wilcox <willy@infradead.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	linux-mm <linux-mm@kvack.org>,
	 linux-m68k@lists.linux-m68k.org,
	 Anshuman Khandual <anshuman.khandual@arm.com>,
	Andrew Morton <akpm@linux-foundation.org>,
	 william.kucharski@oracle.com,
	Mike Kravetz <mike.kravetz@oracle.com>,
	 Vlastimil Babka <vbabka@suse.cz>,
	Geert Uytterhoeven <geert@linux-m68k.org>,
	schmitzmic@gmail.com,  Steven Rostedt <rostedt@goodmis.org>,
	Ingo Molnar <mingo@redhat.com>,
	 Johannes Weiner <hannes@cmpxchg.org>,
	Roman Gushchin <guro@fb.com>,
	Muchun Song <songmuchun@bytedance.com>,
	 weixugc@google.com, Greg Thelen <gthelen@google.com>,
	 David Rientjes <rientjes@google.com>,
	Paul Turner <pjt@google.com>
Subject: Re: [PATCH 00/10] Hardening page _refcount
Date: Wed, 8 Dec 2021 20:23:24 -0500	[thread overview]
Message-ID: <CA+CK2bAnMGOXoszHRnFpmYAceF9K1BJRkf88N__ExgA4o1d2Sg@mail.gmail.com> (raw)
In-Reply-To: <YbEeKiatjGoCD6Yi@casper.infradead.org>

On Wed, Dec 8, 2021 at 4:05 PM Matthew Wilcox <willy@infradead.org> wrote:
>
> On Wed, Dec 08, 2021 at 08:35:34PM +0000, Pasha Tatashin wrote:
> > It is hard to root cause _refcount problems, because they usually
> > manifest after the damage has occurred.  Yet, they can lead to
> > catastrophic failures such memory corruptions. There were a number
> > of refcount related issues discovered recently [1], [2], [3].
> >
> > Improve debugability by adding more checks that ensure that
> > page->_refcount never turns negative (i.e. double free does not
> > happen, or free after freeze etc).
> >
> > - Check for overflow and underflow right from the functions that
> >   modify _refcount
> > - Remove set_page_count(), so we do not unconditionally overwrite
> >   _refcount with an unrestrained value
> > - Trace return values in all functions that modify _refcount
>

Hi Matthew,

Thank you for looking at this series.

> You're doing a lot more atomic instructions with these patches.

This is not exactly so. There are no *more* atomic instructions. There
are, however, different atomic instructions:

For example:  atomic_add() becomes atomic_fetch_add()

On x86 it is:

atomic_add:
    lock add %eax,(%rsi)

atomic_fetch_add:
    lock xadd %eax,(%rsi)

On ARM64, I believe the same CAS instruction is used for both.

  Have you
> done any performance measurements with these patches applied and debug
> disabled?

Yes, I have done some performance tests exactly as you described with
CONFIG_DEBUG_VM disabled and these patches applied.
I tried: hackbench, unixbench, and a few more benchmarks; I did not
see any performance difference.

>  I'm really not convinced it's worth closing
> one-instruction-wide races of this kind when they are "shouldn't ever
> happen" situations.  If the debugging will catch the problem in 99.99%
> of cases and miss 0.01% without using atomic instructions, that seems
> like a better set of tradeoffs than catching 100% of problems by using
> the atomic instructions.

I think we should relax the precise catching of bugs only if there is
indeed a measurable performance impact. The problem is that if there
is a __refcount bug, the security consequences are dire as it may lead
to leaking memory from one process to another.

Thanks,
Pasha


      reply	other threads:[~2021-12-09  1:24 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-08 20:35 Pasha Tatashin
2021-12-08 20:35 ` [PATCH 01/10] mm: page_ref_add_unless() does not trace 'u' argument Pasha Tatashin
2021-12-08 20:55   ` Matthew Wilcox
2021-12-09  1:25     ` Pasha Tatashin
2021-12-09  2:17       ` Matthew Wilcox
2021-12-09 15:15         ` Pasha Tatashin
2021-12-08 20:35 ` [PATCH 02/10] mm: add overflow and underflow checks for page->_refcount Pasha Tatashin
2021-12-08 20:35 ` [PATCH 03/10] mm: Avoid using set_page_count() in set_page_recounted() Pasha Tatashin
2021-12-08 20:35 ` [PATCH 04/10] mm: remove set_page_count() from page_frag_alloc_align Pasha Tatashin
2021-12-08 20:35 ` [PATCH 06/10] mm: rename init_page_count() -> page_ref_init() Pasha Tatashin
2021-12-08 20:35 ` [PATCH 07/10] mm: remove set_page_count() Pasha Tatashin
2021-12-08 20:35 ` [PATCH 08/10] mm: simplify page_ref_* functions Pasha Tatashin
2021-12-08 20:35 ` [PATCH 09/10] mm: do not use atomic_set_release in page_ref_unfreeze() Pasha Tatashin
2021-12-08 20:35 ` [PATCH 10/10] mm: use atomic_cmpxchg_acquire in page_ref_freeze() Pasha Tatashin
2021-12-08 21:05 ` [PATCH 00/10] Hardening page _refcount Matthew Wilcox
2021-12-09  1:23   ` Pasha Tatashin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CA+CK2bAnMGOXoszHRnFpmYAceF9K1BJRkf88N__ExgA4o1d2Sg@mail.gmail.com \
    --to=pasha.tatashin@soleen.com \
    --cc=akpm@linux-foundation.org \
    --cc=anshuman.khandual@arm.com \
    --cc=geert@linux-m68k.org \
    --cc=gthelen@google.com \
    --cc=guro@fb.com \
    --cc=hannes@cmpxchg.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-m68k@lists.linux-m68k.org \
    --cc=linux-mm@kvack.org \
    --cc=mike.kravetz@oracle.com \
    --cc=mingo@redhat.com \
    --cc=pjt@google.com \
    --cc=rientjes@google.com \
    --cc=rostedt@goodmis.org \
    --cc=schmitzmic@gmail.com \
    --cc=songmuchun@bytedance.com \
    --cc=vbabka@suse.cz \
    --cc=weixugc@google.com \
    --cc=william.kucharski@oracle.com \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox