lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAHk-=wjv+beg2gRNdERANGfaGcqwDzzVD5RDD07FcrE5c6k-XA@mail.gmail.com>
Date:   Thu, 13 Jan 2022 09:44:04 -0800
From:   Linus Torvalds <torvalds@...ux-foundation.org>
To:     David Hildenbrand <david@...hat.com>
Cc:     Matthew Wilcox <willy@...radead.org>,
        Liang Zhang <zhangliang5@...wei.com>,
        Andrew Morton <akpm@...ux-foundation.org>,
        Linux-MM <linux-mm@...ck.org>,
        Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
        wangzhigang17@...wei.com
Subject: Re: [PATCH] mm: reuse the unshared swapcache page in do_wp_page

On Thu, Jan 13, 2022 at 9:25 AM David Hildenbrand <david@...hat.com> wrote:
>
> I might be missing something, but it's not only about whether we can remove
> the page from the swap cache, it's about whether we can reuse the page
> exclusively in a process with write access, avoiding a COW. And for that we
> have to check if it's mapped somewhere else already (readable).

No.

The "try to remove from swap cache" is one thing. That uses the swap count.

The "see if we can reuse this page for COW" is a completely different
test, and that's the "page_count() == 1" one.

The two should not be mixed up with each other. Just don't do it.
There's no reason - except for legacy confusion that should be
actively avoided and removed.

IOW, the COW path would do

 trylock - copy if fails
 try to remove from swap cache
 if page_count() is now 1, we can reuse it

Note how the "try to remove from swap cache" is entirely independent
of whether we then reuse it or not.

And yes, we can have optimistic other tests - like not even bothering
to trylock if we can see that the page-count is so elevated that it
makes no difference and trying to remove from swap cache would be just
pointless extra work (both the removal itself, and then potentially
later re-additions).

But those should be seen for what they are - not important for
semantics, only a "don't bother, this page has so many users that we
already know that removing the swapcache one doesn't make any
difference at all".

Now, it's possible that I'm missing something, but I think this kind
of clarity is very much what we should aim for. Clear rules, no mixing
of "can I COW this" with "can I remove this from the swap cache".

And now I need to start my travel nightmare, so I'll be effectively
offline for the next 24 hours ;(

              Linus

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ