All of lore.kernel.org
 help / color / mirror / Atom feed
* fix memcpy_to_page and memzero_page
@ 2021-07-13  5:52 Christoph Hellwig
  2021-07-13  5:52 ` [PATCH 1/2] mm: call flush_dcache_page in " Christoph Hellwig
  2021-07-13  5:52 ` [PATCH 2/2] mm: use kmap_local_page in memzero_page Christoph Hellwig
  0 siblings, 2 replies; 6+ messages in thread
From: Christoph Hellwig @ 2021-07-13  5:52 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Ira Weiny, linux-kernel, linux-mm

Hi all,

we need to call flush_dcache_page on any kmapped page, and on any page
we write to that may be mapped into the page cache, which can happen
quite frequently for anything we use raw pages for.

Patch 1 make sure memcpy_to_page and memzero_page to do the right thing
for that, and patch 2 fixes up the lost switch to kmap_local_page for
memzero_page.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] mm: call flush_dcache_page in memcpy_to_page and memzero_page
  2021-07-13  5:52 fix memcpy_to_page and memzero_page Christoph Hellwig
@ 2021-07-13  5:52 ` Christoph Hellwig
  2021-07-14  1:31   ` Andrew Morton
  2021-07-14  8:09   ` Ira Weiny
  2021-07-13  5:52 ` [PATCH 2/2] mm: use kmap_local_page in memzero_page Christoph Hellwig
  1 sibling, 2 replies; 6+ messages in thread
From: Christoph Hellwig @ 2021-07-13  5:52 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Ira Weiny, linux-kernel, linux-mm

memcpy_to_page and memzero_page can write to arbitrary pages, which could
be in the page cache or in high memory, so  call flush_kernel_dcache_pages
to flush the dcache.

Fixes: bb90d4bc7b6a ("mm/highmem: Lift memcpy_[to|from]_page to core")
Fixes: 28961998f858 ("iov_iter: lift memzero_page() to highmem.h")
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
 include/linux/highmem.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/include/linux/highmem.h b/include/linux/highmem.h
index 8c6e8e996c87..8e7e50a53a12 100644
--- a/include/linux/highmem.h
+++ b/include/linux/highmem.h
@@ -318,6 +318,7 @@ static inline void memcpy_to_page(struct page *page, size_t offset,
 
 	VM_BUG_ON(offset + len > PAGE_SIZE);
 	memcpy(to + offset, from, len);
+	flush_dcache_page(page);
 	kunmap_local(to);
 }
 
@@ -325,6 +326,7 @@ static inline void memzero_page(struct page *page, size_t offset, size_t len)
 {
 	char *addr = kmap_atomic(page);
 	memset(addr + offset, 0, len);
+	flush_dcache_page(page);
 	kunmap_atomic(addr);
 }
 
-- 
2.30.2


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/2] mm: use kmap_local_page in memzero_page
  2021-07-13  5:52 fix memcpy_to_page and memzero_page Christoph Hellwig
  2021-07-13  5:52 ` [PATCH 1/2] mm: call flush_dcache_page in " Christoph Hellwig
@ 2021-07-13  5:52 ` Christoph Hellwig
  1 sibling, 0 replies; 6+ messages in thread
From: Christoph Hellwig @ 2021-07-13  5:52 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Ira Weiny, linux-kernel, linux-mm, Chaitanya Kulkarni

The commit message introducing the global memzero_page explicitly
mentions switching to kmap_local_page in the commit log but doesn't
actually do that.

Fixes: 28961998f858 ("iov_iter: lift memzero_page() to highmem.h")
Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Reviewed-by: Ira Weiny <ira.weiny@intel.com>
---
 include/linux/highmem.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/highmem.h b/include/linux/highmem.h
index 8e7e50a53a12..d9a606a9fc64 100644
--- a/include/linux/highmem.h
+++ b/include/linux/highmem.h
@@ -324,10 +324,10 @@ static inline void memcpy_to_page(struct page *page, size_t offset,
 
 static inline void memzero_page(struct page *page, size_t offset, size_t len)
 {
-	char *addr = kmap_atomic(page);
+	char *addr = kmap_local_page(page);
 	memset(addr + offset, 0, len);
 	flush_dcache_page(page);
-	kunmap_atomic(addr);
+	kunmap_local(addr);
 }
 
 #endif /* _LINUX_HIGHMEM_H */
-- 
2.30.2


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] mm: call flush_dcache_page in memcpy_to_page and memzero_page
  2021-07-13  5:52 ` [PATCH 1/2] mm: call flush_dcache_page in " Christoph Hellwig
@ 2021-07-14  1:31   ` Andrew Morton
  2021-07-14  5:28     ` Christoph Hellwig
  2021-07-14  8:09   ` Ira Weiny
  1 sibling, 1 reply; 6+ messages in thread
From: Andrew Morton @ 2021-07-14  1:31 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Ira Weiny, linux-kernel, linux-mm

On Tue, 13 Jul 2021 07:52:30 +0200 Christoph Hellwig <hch@lst.de> wrote:

> memcpy_to_page and memzero_page can write to arbitrary pages, which could
> be in the page cache or in high memory, so  call flush_kernel_dcache_pages
> to flush the dcache.

I assume this presently is not known to cause any problems, but that
some problems might be discovered in the future?  In which case,
should we cc:stable?


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] mm: call flush_dcache_page in memcpy_to_page and memzero_page
  2021-07-14  1:31   ` Andrew Morton
@ 2021-07-14  5:28     ` Christoph Hellwig
  0 siblings, 0 replies; 6+ messages in thread
From: Christoph Hellwig @ 2021-07-14  5:28 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Christoph Hellwig, Ira Weiny, linux-kernel, linux-mm

On Tue, Jul 13, 2021 at 06:31:23PM -0700, Andrew Morton wrote:
> On Tue, 13 Jul 2021 07:52:30 +0200 Christoph Hellwig <hch@lst.de> wrote:
> 
> > memcpy_to_page and memzero_page can write to arbitrary pages, which could
> > be in the page cache or in high memory, so  call flush_kernel_dcache_pages
> > to flush the dcache.
> 
> I assume this presently is not known to cause any problems, but that
> some problems might be discovered in the future?  In which case,
> should we cc:stable?

This is a problem when using these helpers on dcache challeneged
architectures.  Right now there are just a few users, chances
are no one used the PC floppy drіver, the aha1542 driver for an ISA
SCSI HBA, and a few advanced and optional btrfs and ext4 features
on those platforms yet since the conversion.  So yes, stable would be
good.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] mm: call flush_dcache_page in memcpy_to_page and memzero_page
  2021-07-13  5:52 ` [PATCH 1/2] mm: call flush_dcache_page in " Christoph Hellwig
  2021-07-14  1:31   ` Andrew Morton
@ 2021-07-14  8:09   ` Ira Weiny
  1 sibling, 0 replies; 6+ messages in thread
From: Ira Weiny @ 2021-07-14  8:09 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Andrew Morton, linux-kernel, linux-mm

On Tue, Jul 13, 2021 at 07:52:30AM +0200, Christoph Hellwig wrote:
> memcpy_to_page and memzero_page can write to arbitrary pages, which could
> be in the page cache or in high memory, so  call flush_kernel_dcache_pages
> to flush the dcache.
> 
> Fixes: bb90d4bc7b6a ("mm/highmem: Lift memcpy_[to|from]_page to core")
> Fixes: 28961998f858 ("iov_iter: lift memzero_page() to highmem.h")
> Signed-off-by: Christoph Hellwig <hch@lst.de>

Reviewed-by: Ira Weiny <ira.weiny@intel.com>

> ---
>  include/linux/highmem.h | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/include/linux/highmem.h b/include/linux/highmem.h
> index 8c6e8e996c87..8e7e50a53a12 100644
> --- a/include/linux/highmem.h
> +++ b/include/linux/highmem.h
> @@ -318,6 +318,7 @@ static inline void memcpy_to_page(struct page *page, size_t offset,
>  
>  	VM_BUG_ON(offset + len > PAGE_SIZE);
>  	memcpy(to + offset, from, len);
> +	flush_dcache_page(page);
>  	kunmap_local(to);
>  }
>  
> @@ -325,6 +326,7 @@ static inline void memzero_page(struct page *page, size_t offset, size_t len)
>  {
>  	char *addr = kmap_atomic(page);
>  	memset(addr + offset, 0, len);
> +	flush_dcache_page(page);
>  	kunmap_atomic(addr);
>  }
>  
> -- 
> 2.30.2
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-07-14  8:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-13  5:52 fix memcpy_to_page and memzero_page Christoph Hellwig
2021-07-13  5:52 ` [PATCH 1/2] mm: call flush_dcache_page in " Christoph Hellwig
2021-07-14  1:31   ` Andrew Morton
2021-07-14  5:28     ` Christoph Hellwig
2021-07-14  8:09   ` Ira Weiny
2021-07-13  5:52 ` [PATCH 2/2] mm: use kmap_local_page in memzero_page Christoph Hellwig

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.