Skip to content

Commit bb90d4b

Browse files
weiny2kdave
authored andcommitted
mm/highmem: Lift memcpy_[to|from]_page to core
Working through a conversion to a call kmap_local_page() instead of kmap() revealed many places where the pattern kmap/memcpy/kunmap occurred. Eric Biggers, Matthew Wilcox, Christoph Hellwig, Dan Williams, and Al Viro all suggested putting this code into helper functions. Al Viro further pointed out that these functions already existed in the iov_iter code.[1] Various locations for the lifted functions were considered. Headers like mm.h or string.h seem ok but don't really portray the functionality well. pagemap.h made some sense but is for page cache functionality.[2] Another alternative would be to create a new header for the promoted memcpy functions, but it masks the fact that these are designed to copy to/from pages using the kernel direct mappings and complicates matters with a new header. Placing these functions in 'highmem.h' is suboptimal especially with the changes being proposed in the functionality of kmap. From a caller perspective including/using 'highmem.h' implies that the functions defined in that header are only required when highmem is in use which is increasingly not the case with modern processors. However, highmem.h is where all the current functions like this reside (zero_user(), clear_highpage(), clear_user_highpage(), copy_user_highpage(), and copy_highpage()). So it makes the most sense even though it is distasteful for some.[3] Lift memcpy_to_page() and memcpy_from_page() to pagemap.h. [1] https://lore.kernel.org/lkml/[email protected]/ https://lore.kernel.org/lkml/[email protected]/ [2] https://lore.kernel.org/lkml/[email protected]/ [3] https://lore.kernel.org/lkml/[email protected]/#t https://lore.kernel.org/lkml/[email protected]/ Cc: Boris Pismenny <[email protected]> Cc: Or Gerlitz <[email protected]> Cc: Dave Hansen <[email protected]> Suggested-by: Matthew Wilcox <[email protected]> Suggested-by: Christoph Hellwig <[email protected]> Suggested-by: Dan Williams <[email protected]> Suggested-by: Al Viro <[email protected]> Suggested-by: Eric Biggers <[email protected]> Reviewed-by: Chaitanya Kulkarni <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Ira Weiny <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 92bf226 commit bb90d4b

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

include/linux/highmem.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,4 +276,22 @@ static inline void copy_highpage(struct page *to, struct page *from)
276276

277277
#endif
278278

279+
static inline void memcpy_from_page(char *to, struct page *page,
280+
size_t offset, size_t len)
281+
{
282+
char *from = kmap_atomic(page);
283+
284+
memcpy(to, from + offset, len);
285+
kunmap_atomic(from);
286+
}
287+
288+
static inline void memcpy_to_page(struct page *page, size_t offset,
289+
const char *from, size_t len)
290+
{
291+
char *to = kmap_atomic(page);
292+
293+
memcpy(to + offset, from, len);
294+
kunmap_atomic(to);
295+
}
296+
279297
#endif /* _LINUX_HIGHMEM_H */

lib/iov_iter.c

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -466,20 +466,6 @@ void iov_iter_init(struct iov_iter *i, unsigned int direction,
466466
}
467467
EXPORT_SYMBOL(iov_iter_init);
468468

469-
static void memcpy_from_page(char *to, struct page *page, size_t offset, size_t len)
470-
{
471-
char *from = kmap_atomic(page);
472-
memcpy(to, from + offset, len);
473-
kunmap_atomic(from);
474-
}
475-
476-
static void memcpy_to_page(struct page *page, size_t offset, const char *from, size_t len)
477-
{
478-
char *to = kmap_atomic(page);
479-
memcpy(to + offset, from, len);
480-
kunmap_atomic(to);
481-
}
482-
483469
static void memzero_page(struct page *page, size_t offset, size_t len)
484470
{
485471
char *addr = kmap_atomic(page);

0 commit comments

Comments
 (0)