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: <YRiKdCEDHKZ4T0JY@casper.infradead.org>
Date:   Sun, 15 Aug 2021 04:31:00 +0100
From:   Matthew Wilcox <willy@...radead.org>
To:     Vlastimil Babka <vbabka@...e.cz>
Cc:     linux-kernel@...r.kernel.org, linux-mm@...ck.org,
        linux-fsdevel@...r.kernel.org, Christoph Hellwig <hch@....de>
Subject: Re: [PATCH v14 071/138] mm/writeback: Add filemap_dirty_folio()

On Thu, Aug 12, 2021 at 06:07:05PM +0200, Vlastimil Babka wrote:
> On 7/15/21 5:35 AM, Matthew Wilcox (Oracle) wrote:
> > Reimplement __set_page_dirty_nobuffers() as a wrapper around
> > filemap_dirty_folio().
> 
> I assume it becomes obvious later why the new "mapping" parameter instead of
> taking it from the folio, but maybe the changelog should say it here?

---

mm/writeback: Add filemap_dirty_folio()

Reimplement __set_page_dirty_nobuffers() as a wrapper around
filemap_dirty_folio().  Eventually folio_mark_dirty() will pass
the folio's mapping to the address space's ->dirty_folio()
operation, so add the parameter to filemap_dirty_folio() now.

---

Nobody seems quite sure whether it's possible to truncate (or otherwise
remove) a page from a file while it's being marked as dirty.  viz:

int set_page_dirty(struct page *page)
{
        struct address_space *mapping = page_mapping(page);
        if (likely(mapping)) {
...
                return mapping->a_ops->set_page_dirty(page);
}

so ->set_page_dirty can only be called if page has a mapping (obviously,
otherwise we wouldn't know whose ->set_page_dirty to call).  But then
in __set_page_dirty_nobuffers(), we check to see if mapping has
become unset:

        if (!TestSetPageDirty(page)) {
                struct address_space *mapping = page_mapping(page);

                if (!mapping) {
                        unlock_page_memcg(page);
                        return 1;
                }

Confusingly, the comment to __set_page_dirty_nobuffers says:

 * The caller must ensure this doesn't race with truncation.  Most will simply
 * hold the page lock, but e.g. zap_pte_range() calls with the page mapped and
 * the pte lock held, which also locks out truncation.

I believe this is left-over from commit 2d6d7f982846 in 2015.

Anyway, passing mapping as a parameter is something we already do for
just about every other address_space operation, and we already called
page_mapping() to get it, so why make the callee call it again?  Not to
mention people get confused about whether to call page_mapping() or just
look at page->mapping.  Changing the ->set_page_dirty() operation to
->dirty_folio() is something I've postponed until the 5.17/5.18 timeframe,
but we might as well pass the parameter to filemap_dirty_folio() now.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ