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: <e5d41fbe-a91b-9491-7b93-733f67e75a54@redhat.com>
Date:   Mon, 2 Oct 2023 19:30:35 +0200
From:   David Hildenbrand <david@...hat.com>
To:     Peter Xu <peterx@...hat.com>
Cc:     Suren Baghdasaryan <surenb@...gle.com>, akpm@...ux-foundation.org,
        viro@...iv.linux.org.uk, brauner@...nel.org, shuah@...nel.org,
        aarcange@...hat.com, lokeshgidra@...gle.com, hughd@...gle.com,
        mhocko@...e.com, axelrasmussen@...gle.com, rppt@...nel.org,
        willy@...radead.org, Liam.Howlett@...cle.com, jannh@...gle.com,
        zhangpeng362@...wei.com, bgeffon@...gle.com,
        kaleshsingh@...gle.com, ngeoffray@...gle.com, jdduke@...gle.com,
        linux-mm@...ck.org, linux-fsdevel@...r.kernel.org,
        linux-kernel@...r.kernel.org, linux-kselftest@...r.kernel.org,
        kernel-team@...roid.com
Subject: Re: [PATCH v2 1/3] userfaultfd: UFFDIO_REMAP: rmap preparation

On 02.10.23 17:23, Peter Xu wrote:
> On Mon, Oct 02, 2023 at 04:42:50PM +0200, David Hildenbrand wrote:
>> On 23.09.23 03:31, Suren Baghdasaryan wrote:
>>> From: Andrea Arcangeli <aarcange@...hat.com>
>>>
>>> As far as the rmap code is concerned, UFFDIO_REMAP only alters the
>>> page->mapping and page->index. It does it while holding the page
>>> lock. However folio_referenced() is doing rmap walks without taking the
>>> folio lock first, so folio_lock_anon_vma_read() must be updated to
>>> re-check that the folio->mapping didn't change after we obtained the
>>> anon_vma read lock.
>>
>> I'm curious: why don't we need this for existing users of
>> page_move_anon_rmap()? What's special about UFFDIO_REMAP?
> 
> Totally no expert on anon vma so I'm prone to errors, but IIUC the
> difference here is root anon vma cannot change in page_move_anon_rmap(),
> while UFFDIO_REMAP can.

That does sound reasonable, thanks.

Probably we can do better with the patch description (once [1] is used 
to move the folio to the other anon_vma).

"mm/rmap: support move to different root anon_vma in folio_move_anon_rmap()

For now, folio_move_anon_rmap() was only used to move a folio to a 
different anon_vma after fork(), whereby the root anon_vma stayed 
unchanged. For that, it was sufficient to hold the page lock when 
calling folio_move_anon_rmap().

However, we want to make use of folio_move_anon_rmap() to move folios 
between VMAs that have a different root anon_vma. As folio_referenced() 
performs an RMAP walk without holding the page lock but only holding the 
anon_vma in read mode, holding the page lock is insufficient.

When moving to an anon_vma with a different root anon_vma, we'll have to 
hold both, the page lock and the anon_vma lock in write mode. 
Consequently, whenever we succeeded in folio_lock_anon_vma_read() to 
read-lock the anon_vma, we have to re-check if the mapping was changed 
in the meantime. If that was the case, we have to retry.

Note that folio_move_anon_rmap() must only be called if the anon page is 
exclusive to a process, and must not be called on KSM folios.

This is a preparation for UFFDIO_REMAP, which will hold the page lock, 
the anon_vma lock in write mode, and the mmap_lock in read mode.
"

In addition, we should document these locking details for 
folio_move_anon_rmap() and probably not mention UFFDIO_REMAP in the 
comment in folio_lock_anon_vma_read(), but instead say 
"folio_move_anon_rmap() might have changed the anon_vma as we might not 
hold the page lock here."


[1] https://lkml.kernel.org/r/20231002142949.235104-3-david@redhat.com

-- 
Cheers,

David / dhildenb

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ