Skip to contentSkip to conversation

mm/highmem: Delete memmove_page()

PATCH In review Fabio M. De Francesco 3 participants 3 messages Jun 6, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/highmem: Delete memmove_page()

Matthew Wilcox reported that, while he was looking at memmove_page(), he realized that it can't actually work.

The reasons are hidden in its implementation, which makes use of memmove() on logical addresses provided by kmap_local_page(). memmove() does the wrong thing when it tests "if (dest <= src)".

Therefore, delete memmove_page().

No need to change any other code because we have no call sites of memmove_page() across the whole kernel.

---
 include/linux/highmem.h | 13 -------------
 1 file changed, 13 deletions(-)
include/linux/highmem.h +0 -13
index 3af34de54330..fee9835e3793 100644
@@ -336,19 +336,6 @@ static inline void memcpy_page(struct page *dst_page, size_t dst_off,
 	kunmap_local(dst);
 }
 
-static inline void memmove_page(struct page *dst_page, size_t dst_off,
-			       struct page *src_page, size_t src_off,
-			       size_t len)
-{
-	char *dst = kmap_local_page(dst_page);
-	char *src = kmap_local_page(src_page);
-
-	VM_BUG_ON(dst_off + len > PAGE_SIZE || src_off + len > PAGE_SIZE);
-	memmove(dst + dst_off, src + src_off, len);
-	kunmap_local(src);
-	kunmap_local(dst);
-}
-
 static inline void memset_page(struct page *page, size_t offset, int val,
 			       size_t len)
 {
Signature · 1 line
2.36.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Fabio M. De Francesco

Matthew Wilcox reported that, while he was looking at memmove_page(), he realized that it can't actually work.

The reasons are hidden in its implementation, which makes use of memmove() on logical addresses provided by kmap_local_page(). memmove() does the wrong thing when it tests "if (dest <= src)".

Therefore, delete memmove_page().

No need to change any other code because we have no call sites of memmove_page() across the whole kernel.

Nice clean up.

Quoted 36 lines
---
 include/linux/highmem.h | 13 -------------
 1 file changed, 13 deletions(-)
include/linux/highmem.h +0 -13
index 3af34de54330..fee9835e3793 100644
@@ -336,19 +336,6 @@ static inline void memcpy_page(struct page *dst_page, size_t dst_off,
 	kunmap_local(dst);
 }
 
-static inline void memmove_page(struct page *dst_page, size_t dst_off,
-			       struct page *src_page, size_t src_off,
-			       size_t len)
-{
-	char *dst = kmap_local_page(dst_page);
-	char *src = kmap_local_page(src_page);
-
-	VM_BUG_ON(dst_off + len > PAGE_SIZE || src_off + len > PAGE_SIZE);
-	memmove(dst + dst_off, src + src_off, len);
-	kunmap_local(src);
-	kunmap_local(dst);
-}
-
 static inline void memset_page(struct page *page, size_t offset, int val,
 			       size_t len)
 {
Signature · 1 line
2.36.1
Reviewed-by on v1 1/1
#2 lore raw
In reply to Fabio M. De Francesco
Quoted 7 lines · Fabio M. De Francesco

Matthew Wilcox reported that, while he was looking at memmove_page(), he realized that it can't actually work.

The reasons are hidden in its implementation, which makes use of memmove() on logical addresses provided by kmap_local_page(). memmove() does the wrong thing when it tests "if (dest <= src)".

Quoted 7 lines

Therefore, delete memmove_page().

No need to change any other code because we have no call sites of memmove_page() across the whole kernel.

Quoted 32 lines
---
 include/linux/highmem.h | 13 -------------
 1 file changed, 13 deletions(-)
include/linux/highmem.h +0 -13
index 3af34de54330..fee9835e3793 100644
@@ -336,19 +336,6 @@ static inline void memcpy_page(struct page *dst_page, size_t dst_off,
 	kunmap_local(dst);
 }
 
-static inline void memmove_page(struct page *dst_page, size_t dst_off,
-			       struct page *src_page, size_t src_off,
-			       size_t len)
-{
-	char *dst = kmap_local_page(dst_page);
-	char *src = kmap_local_page(src_page);
-
-	VM_BUG_ON(dst_off + len > PAGE_SIZE || src_off + len > PAGE_SIZE);
-	memmove(dst + dst_off, src + src_off, len);
-	kunmap_local(src);
-	kunmap_local(dst);
-}
-
 static inline void memset_page(struct page *page, size_t offset, int val,
 			       size_t len)
 {
Signature · 1 line
2.36.1