From: Matthew Wilcox <willy@infradead.org> To: Christoph Hellwig <hch@infradead.org> Cc: Andreas Gruenbacher <agruenba@redhat.com>, "Darrick J . Wong" <djwong@kernel.org>, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, Gao Xiang <xiang@kernel.org>, linux-erofs@lists.ozlabs.org, stable@vger.kernel.org, Christoph Lameter <cl@linux.com> Subject: Re: [PATCH] iomap: Add missing flush_dcache_page Date: Tue, 20 Jul 2021 16:56:10 +0100 [thread overview] Message-ID: <YPbyGnpwsaC006Rk@casper.infradead.org> (raw) In-Reply-To: <YPU6NVlfIh4PfbPl@infradead.org> On Mon, Jul 19, 2021 at 09:39:17AM +0100, Christoph Hellwig wrote: > On Fri, Jul 16, 2021 at 06:28:10PM +0100, Matthew Wilcox wrote: > > > > memcpy(addr, iomap->inline_data, size); > > > > memset(addr + size, 0, PAGE_SIZE - size); > > > > kunmap_atomic(addr); > > > > + flush_dcache_page(page); > > > > > > .. and all writes into a kmap also need such a flush, so this needs to > > > move a line up. My plan was to add a memcpy_to_page_and_pad helper > > > ala memcpy_to_page to get various file systems and drivers out of the > > > business of cache flushing as much as we can. > > > > hm? It's absolutely allowed to flush the page after calling kunmap. > > Look at zero_user_segments(), for example. > > Documentation/core-api/cachetlb.rst states that any user page obtained > using kmap needs a flush_kernel_dcache_page after modification. > flush_dcache_page is a strict superset of flush_kernel_dcache_page. Looks like (the other) Christoph broke this in 2008 with commit eebd2aa35569 ("Pagecache zeroing: zero_user_segment, zero_user_segments and zero_user"): It has one line about it in the changelog: Also extract the flushing of the caches to be outside of the kmap. ... which doesn't even attempt to justify why it's safe to do so. - memset((char *)kaddr + (offset), 0, (size)); \ - flush_dcache_page(page); \ - kunmap_atomic(kaddr, (km_type)); \ + kunmap_atomic(kaddr, KM_USER0); + flush_dcache_page(page); Looks like it came from https://lore.kernel.org/lkml/20070911060425.472862098@sgi.com/ but there was no discussion of this ... plenty of discussion about other conceptual problems with the entire patchset. > That beeing said flushing after kmap updates is a complete mess. > arm as probably the poster child for dcache challenged plus highmem > architectures always flushed caches from kunmap and, and arc has > a flush_dcache_page that doesn't work at all on a highmem page that > is not kmapped (where kmap_atomic and kmap_local_page don't count as > kmapped as they don't set page->virtual).
WARNING: multiple messages have this Message-ID (diff)
From: Matthew Wilcox <willy@infradead.org> To: Christoph Hellwig <hch@infradead.org> Cc: Andreas Gruenbacher <agruenba@redhat.com>, "Darrick J . Wong" <djwong@kernel.org>, stable@vger.kernel.org, linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, Gao Xiang <xiang@kernel.org>, linux-erofs@lists.ozlabs.org, Christoph Lameter <cl@linux.com> Subject: Re: [PATCH] iomap: Add missing flush_dcache_page Date: Tue, 20 Jul 2021 16:56:10 +0100 [thread overview] Message-ID: <YPbyGnpwsaC006Rk@casper.infradead.org> (raw) In-Reply-To: <YPU6NVlfIh4PfbPl@infradead.org> On Mon, Jul 19, 2021 at 09:39:17AM +0100, Christoph Hellwig wrote: > On Fri, Jul 16, 2021 at 06:28:10PM +0100, Matthew Wilcox wrote: > > > > memcpy(addr, iomap->inline_data, size); > > > > memset(addr + size, 0, PAGE_SIZE - size); > > > > kunmap_atomic(addr); > > > > + flush_dcache_page(page); > > > > > > .. and all writes into a kmap also need such a flush, so this needs to > > > move a line up. My plan was to add a memcpy_to_page_and_pad helper > > > ala memcpy_to_page to get various file systems and drivers out of the > > > business of cache flushing as much as we can. > > > > hm? It's absolutely allowed to flush the page after calling kunmap. > > Look at zero_user_segments(), for example. > > Documentation/core-api/cachetlb.rst states that any user page obtained > using kmap needs a flush_kernel_dcache_page after modification. > flush_dcache_page is a strict superset of flush_kernel_dcache_page. Looks like (the other) Christoph broke this in 2008 with commit eebd2aa35569 ("Pagecache zeroing: zero_user_segment, zero_user_segments and zero_user"): It has one line about it in the changelog: Also extract the flushing of the caches to be outside of the kmap. ... which doesn't even attempt to justify why it's safe to do so. - memset((char *)kaddr + (offset), 0, (size)); \ - flush_dcache_page(page); \ - kunmap_atomic(kaddr, (km_type)); \ + kunmap_atomic(kaddr, KM_USER0); + flush_dcache_page(page); Looks like it came from https://lore.kernel.org/lkml/20070911060425.472862098@sgi.com/ but there was no discussion of this ... plenty of discussion about other conceptual problems with the entire patchset. > That beeing said flushing after kmap updates is a complete mess. > arm as probably the poster child for dcache challenged plus highmem > architectures always flushed caches from kunmap and, and arc has > a flush_dcache_page that doesn't work at all on a highmem page that > is not kmapped (where kmap_atomic and kmap_local_page don't count as > kmapped as they don't set page->virtual).
next prev parent reply other threads:[~2021-07-20 16:08 UTC|newest] Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-07-16 15:00 [PATCH] iomap: Add missing flush_dcache_page Matthew Wilcox (Oracle) 2021-07-16 15:00 ` Matthew Wilcox (Oracle) 2021-07-16 15:04 ` Christoph Hellwig 2021-07-16 15:04 ` Christoph Hellwig 2021-07-16 17:28 ` Matthew Wilcox 2021-07-16 17:28 ` Matthew Wilcox 2021-07-19 8:39 ` Christoph Hellwig 2021-07-19 8:39 ` Christoph Hellwig 2021-07-20 15:56 ` Matthew Wilcox [this message] 2021-07-20 15:56 ` Matthew Wilcox 2021-07-16 15:04 ` Gao Xiang 2021-07-16 15:04 ` Gao Xiang
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=YPbyGnpwsaC006Rk@casper.infradead.org \ --to=willy@infradead.org \ --cc=agruenba@redhat.com \ --cc=cl@linux.com \ --cc=djwong@kernel.org \ --cc=hch@infradead.org \ --cc=linux-erofs@lists.ozlabs.org \ --cc=linux-fsdevel@vger.kernel.org \ --cc=linux-xfs@vger.kernel.org \ --cc=stable@vger.kernel.org \ --cc=xiang@kernel.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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.