All of lore.kernel.org
 help / color / mirror / Atom feed
From: ira.weiny@intel.com
To: Andrew Morton <akpm@linux-foundation.org>
Cc: "Ira Weiny" <ira.weiny@intel.com>,
	"Dave Hansen" <dave.hansen@intel.com>,
	"Matthew Wilcox" <willy@infradead.org>,
	"Christoph Hellwig" <hch@infradead.org>,
	"Dan Williams" <dan.j.williams@intel.com>,
	"Al Viro" <viro@zeniv.linux.org.uk>,
	"Eric Biggers" <ebiggers@kernel.org>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Luis Chamberlain" <mcgrof@kernel.org>,
	"Patrik Jakobsson" <patrik.r.jakobsson@gmail.com>,
	"Jani Nikula" <jani.nikula@linux.intel.com>,
	"Joonas Lahtinen" <joonas.lahtinen@linux.intel.com>,
	"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
	"David Howells" <dhowells@redhat.com>, "Chris Mason" <clm@fb.com>,
	"Josef Bacik" <josef@toxicpanda.com>,
	"David Sterba" <dsterba@suse.com>,
	"Steve French" <sfrench@samba.org>,
	"Jaegeuk Kim" <jaegeuk@kernel.org>,
	"Chao Yu" <yuchao0@huawei.com>,
	"Nicolas Pitre" <nico@fluxnic.net>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	"Brian King" <brking@us.ibm.com>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	"Alexei Starovoitov" <ast@kernel.org>,
	"Daniel Borkmann" <daniel@iogearbox.net>,
	"Jérôme Glisse" <jglisse@redhat.com>,
	"Kirti Wankhede" <kwankhede@nvidia.com>,
	linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: [PATCH 01/17] mm/highmem: Lift memcpy_[to|from]_page and memset_page to core
Date: Mon, 23 Nov 2020 22:07:39 -0800	[thread overview]
Message-ID: <20201124060755.1405602-2-ira.weiny@intel.com> (raw)
In-Reply-To: <20201124060755.1405602-1-ira.weiny@intel.com>

From: Ira Weiny <ira.weiny@intel.com>

Working through a conversion to a call such as kmap_thread() 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]

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.  Some headers like
mm.h or string.h seem ok but don't really portray the functionality
well.  'pagemap.h', on the other hand, makes sense and is already
included in many of the places we want to convert.

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.

Lift memcpy_to_page(), memcpy_from_page(), and memzero_page() to
pagemap.h.

Also, add a memcpy_page(), memmove_page, and memset_page() to cover more
kmap/mem*/kunmap. patterns.

[1] https://lore.kernel.org/lkml/20201013200149.GI3576660@ZenIV.linux.org.uk/
    https://lore.kernel.org/lkml/20201013112544.GA5249@infradead.org/

Cc: Dave Hansen <dave.hansen@intel.com>
Suggested-by: Matthew Wilcox <willy@infradead.org>
Suggested-by: Christoph Hellwig <hch@infradead.org>
Suggested-by: Dan Williams <dan.j.williams@intel.com>
Suggested-by: Al Viro <viro@zeniv.linux.org.uk>
Suggested-by: Eric Biggers <ebiggers@kernel.org>
Signed-off-by: Ira Weiny <ira.weiny@intel.com>
---
 include/linux/pagemap.h | 49 +++++++++++++++++++++++++++++++++++++++++
 lib/iov_iter.c          | 21 ------------------
 2 files changed, 49 insertions(+), 21 deletions(-)

diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index c77b7c31b2e4..82a0af6bc843 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -1028,4 +1028,53 @@ unsigned int i_blocks_per_page(struct inode *inode, struct page *page)
 {
 	return thp_size(page) >> inode->i_blkbits;
 }
+
+static inline void memcpy_page(struct page *dst_page, size_t dst_off,
+			       struct page *src_page, size_t src_off,
+			       size_t len)
+{
+	char *dst = kmap_atomic(dst_page);
+	char *src = kmap_atomic(src_page);
+	memcpy(dst + dst_off, src + src_off, len);
+	kunmap_atomic(src);
+	kunmap_atomic(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_atomic(dst_page);
+	char *src = kmap_atomic(src_page);
+	memmove(dst + dst_off, src + src_off, len);
+	kunmap_atomic(src);
+	kunmap_atomic(dst);
+}
+
+static inline void memcpy_from_page(char *to, struct page *page, size_t offset, size_t len)
+{
+	char *from = kmap_atomic(page);
+	memcpy(to, from + offset, len);
+	kunmap_atomic(from);
+}
+
+static inline void memcpy_to_page(struct page *page, size_t offset, const char *from, size_t len)
+{
+	char *to = kmap_atomic(page);
+	memcpy(to + offset, from, len);
+	kunmap_atomic(to);
+}
+
+static inline void memset_page(struct page *page, int val, size_t offset, size_t len)
+{
+	char *addr = kmap_atomic(page);
+	memset(addr + offset, val, len);
+	kunmap_atomic(addr);
+}
+
+static inline void memzero_page(struct page *page, size_t offset, size_t len)
+{
+	memset_page(page, 0, offset, len);
+}
+
 #endif /* _LINUX_PAGEMAP_H */
diff --git a/lib/iov_iter.c b/lib/iov_iter.c
index 1635111c5bd2..2439a8b4f0d2 100644
--- a/lib/iov_iter.c
+++ b/lib/iov_iter.c
@@ -466,27 +466,6 @@ void iov_iter_init(struct iov_iter *i, unsigned int direction,
 }
 EXPORT_SYMBOL(iov_iter_init);
 
-static void memcpy_from_page(char *to, struct page *page, size_t offset, size_t len)
-{
-	char *from = kmap_atomic(page);
-	memcpy(to, from + offset, len);
-	kunmap_atomic(from);
-}
-
-static void memcpy_to_page(struct page *page, size_t offset, const char *from, size_t len)
-{
-	char *to = kmap_atomic(page);
-	memcpy(to + offset, from, len);
-	kunmap_atomic(to);
-}
-
-static void memzero_page(struct page *page, size_t offset, size_t len)
-{
-	char *addr = kmap_atomic(page);
-	memset(addr + offset, 0, len);
-	kunmap_atomic(addr);
-}
-
 static inline bool allocated(struct pipe_buffer *buf)
 {
 	return buf->ops == &default_pipe_buf_ops;
-- 
2.28.0.rc0.12.gb6a658bd00c9


  reply	other threads:[~2020-11-24  6:08 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-24  6:07 [PATCH 00/17] kmap: Create mem*_page interfaces ira.weiny
2020-11-24  6:07 ` ira.weiny [this message]
2020-11-24 14:19   ` [PATCH 01/17] mm/highmem: Lift memcpy_[to|from]_page and memset_page to core Matthew Wilcox
2020-11-24 19:21     ` Ira Weiny
2020-11-24 20:20       ` Matthew Wilcox
     [not found]   ` <160648238432.10416.12405581766428273347@jlahtine-mobl.ger.corp.intel.com>
2020-11-27 13:20     ` Matthew Wilcox
     [not found]       ` <160672815223.3453.2374529656870007787@jlahtine-mobl.ger.corp.intel.com>
2020-12-03 18:25         ` Ira Weiny
2020-11-24  6:07 ` [PATCH 02/17] drivers/firmware_loader: Use new memcpy_[to|from]_page() ira.weiny
2020-11-24  6:07 ` [PATCH 03/17] drivers/gpu: Convert to mem*_page() ira.weiny
2020-11-27 13:01   ` [Intel-gfx] " Joonas Lahtinen
2020-12-04 16:05     ` Ira Weiny
2020-12-04 16:05       ` [Intel-gfx] " Ira Weiny
2020-12-04 22:33       ` Thomas Gleixner
2020-12-04 22:33         ` [Intel-gfx] " Thomas Gleixner
2020-12-07  6:46         ` Ira Weiny
2020-12-07  6:46           ` [Intel-gfx] " Ira Weiny
2020-12-07 16:19           ` Thomas Gleixner
2020-12-07 16:19             ` [Intel-gfx] " Thomas Gleixner
2020-11-24  6:07 ` [PATCH 04/17] fs/afs: Convert to memzero_page() ira.weiny
2020-11-24  6:07 ` [PATCH 05/17] fs/btrfs: " ira.weiny
2020-11-24 14:12   ` David Sterba
2020-11-24 19:25     ` Ira Weiny
2020-11-24  6:07 ` [PATCH 06/17] fs/hfs: Convert to mem*_page() interface ira.weiny
2020-11-24  6:07 ` [PATCH 07/17] fs/cifs: Convert to memcpy_page() ira.weiny
2020-11-24  6:07 ` [PATCH 08/17] fs/hfsplus: Convert to mem*_page() ira.weiny
2020-11-24  6:07 ` [PATCH 09/17] fs/f2fs: Remove f2fs_copy_page() ira.weiny
2020-11-25  3:27   ` Chao Yu
2020-11-24  6:07 ` [PATCH 10/17] fs/freevxfs: Use memcpy_to_page() ira.weiny
2020-11-24  6:07 ` [PATCH 11/17] fs/reiserfs: Use memcpy_from_page() ira.weiny
2020-11-24  6:07 ` [PATCH 12/17] fs/cramfs: " ira.weiny
2020-11-24 15:20   ` Nicolas Pitre
2020-11-24  6:07 ` [PATCH 13/17] drivers/target: Convert to mem*_page() ira.weiny
2020-11-24  6:07 ` [PATCH 14/17] drivers/scsi: Use memcpy_to_page() ira.weiny
2020-11-24  6:07 ` [PATCH 15/17] drivers/staging: Use memcpy_to/from_page() ira.weiny
2020-11-24  6:07 ` [PATCH 16/17] lib: Use mempcy_to/from_page() ira.weiny
2020-11-24  6:07 ` [PATCH 17/17] samples: Use memcpy_to/from_page() ira.weiny
2020-12-04 10:18 ` [PATCH 04/17] fs/afs: Convert to memzero_page() David Howells

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=20201124060755.1405602-2-ira.weiny@intel.com \
    --to=ira.weiny@intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=ast@kernel.org \
    --cc=brking@us.ibm.com \
    --cc=clm@fb.com \
    --cc=dan.j.williams@intel.com \
    --cc=daniel@iogearbox.net \
    --cc=dave.hansen@intel.com \
    --cc=dhowells@redhat.com \
    --cc=dsterba@suse.com \
    --cc=ebiggers@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=hch@infradead.org \
    --cc=jaegeuk@kernel.org \
    --cc=jani.nikula@linux.intel.com \
    --cc=jglisse@redhat.com \
    --cc=joonas.lahtinen@linux.intel.com \
    --cc=josef@toxicpanda.com \
    --cc=kwankhede@nvidia.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=mcgrof@kernel.org \
    --cc=nico@fluxnic.net \
    --cc=patrik.r.jakobsson@gmail.com \
    --cc=rodrigo.vivi@intel.com \
    --cc=sfrench@samba.org \
    --cc=tglx@linutronix.de \
    --cc=viro@zeniv.linux.org.uk \
    --cc=willy@infradead.org \
    --cc=yuchao0@huawei.com \
    /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: link
Be 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.