[4/4] mm: vmalloc: convert vread() to vread_iter()

Message ID 119871ea9507eac7be5d91db38acdb03981e049e.1679183626.git.lstoakes@gmail.com
State New
Headers
Series convert read_kcore(), vread() to use iterators |

Commit Message

Lorenzo Stoakes March 19, 2023, 12:20 a.m. UTC
  Having previously laid the foundation for converting vread() to an iterator
function, pull the trigger and do so.

This patch attempts to provide minimal refactoring and to reflect the
existing logic as best we can, with the exception of aligned_vread_iter()
which drops the use of the deprecated kmap_atomic() in favour of
kmap_local_page().

All existing logic to zero portions of memory not read remain and there
should be no functional difference other than a performance improvement in
/proc/kcore access to vmalloc regions.

Now we have discarded with the need for a bounce buffer at all in
read_kcore_iter(), we dispense with the one allocated there altogether.

Signed-off-by: Lorenzo Stoakes <lstoakes@gmail.com>
---
 fs/proc/kcore.c         |  21 +--------
 include/linux/vmalloc.h |   3 +-
 mm/vmalloc.c            | 101 +++++++++++++++++++++-------------------
 3 files changed, 57 insertions(+), 68 deletions(-)
  

Comments

kernel test robot March 19, 2023, 1:46 a.m. UTC | #1
Hi Lorenzo,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on akpm-mm/mm-everything]
[also build test WARNING on linus/master v6.3-rc2 next-20230317]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Lorenzo-Stoakes/fs-proc-kcore-Avoid-bounce-buffer-for-ktext-data/20230319-082147
base:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link:    https://lore.kernel.org/r/119871ea9507eac7be5d91db38acdb03981e049e.1679183626.git.lstoakes%40gmail.com
patch subject: [PATCH 4/4] mm: vmalloc: convert vread() to vread_iter()
config: sparc64-randconfig-r015-20230319 (https://download.01.org/0day-ci/archive/20230319/202303190922.Wk376onx-lkp@intel.com/config)
compiler: sparc64-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/a28f374d35bd294a529fcba0b69c8b0e2b66fa6c
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Lorenzo-Stoakes/fs-proc-kcore-Avoid-bounce-buffer-for-ktext-data/20230319-082147
        git checkout a28f374d35bd294a529fcba0b69c8b0e2b66fa6c
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=sparc64 olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=sparc64 SHELL=/bin/bash arch/sparc/vdso/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202303190922.Wk376onx-lkp@intel.com/

All warnings (new ones prefixed by >>):

   In file included from include/linux/wait.h:11,
                    from include/linux/swait.h:8,
                    from include/linux/completion.h:12,
                    from include/linux/mm_types.h:14,
                    from include/linux/uio.h:10,
                    from include/linux/vmalloc.h:12,
                    from include/asm-generic/io.h:994,
                    from arch/sparc/include/asm/io.h:22,
                    from arch/sparc/vdso/vclock_gettime.c:18:
>> arch/sparc/include/asm/current.h:18:30: warning: call-clobbered register used for global register variable
      18 | register struct task_struct *current asm("g4");
         |                              ^~~~~~~
   arch/sparc/vdso/vclock_gettime.c:254:1: warning: no previous prototype for '__vdso_clock_gettime' [-Wmissing-prototypes]
     254 | __vdso_clock_gettime(clockid_t clock, struct __kernel_old_timespec *ts)
         | ^~~~~~~~~~~~~~~~~~~~
   arch/sparc/vdso/vclock_gettime.c:282:1: warning: no previous prototype for '__vdso_clock_gettime_stick' [-Wmissing-prototypes]
     282 | __vdso_clock_gettime_stick(clockid_t clock, struct __kernel_old_timespec *ts)
         | ^~~~~~~~~~~~~~~~~~~~~~~~~~
   arch/sparc/vdso/vclock_gettime.c:307:1: warning: no previous prototype for '__vdso_gettimeofday' [-Wmissing-prototypes]
     307 | __vdso_gettimeofday(struct __kernel_old_timeval *tv, struct timezone *tz)
         | ^~~~~~~~~~~~~~~~~~~
   arch/sparc/vdso/vclock_gettime.c:343:1: warning: no previous prototype for '__vdso_gettimeofday_stick' [-Wmissing-prototypes]
     343 | __vdso_gettimeofday_stick(struct __kernel_old_timeval *tv, struct timezone *tz)
         | ^~~~~~~~~~~~~~~~~~~~~~~~~


vim +18 arch/sparc/include/asm/current.h

^1da177e4c3f41 include/asm-sparc/current.h Linus Torvalds  2005-04-16  16  
ba89f59ab825d4 include/asm-sparc/current.h David S. Miller 2007-11-16  17  #ifdef CONFIG_SPARC64
ba89f59ab825d4 include/asm-sparc/current.h David S. Miller 2007-11-16 @18  register struct task_struct *current asm("g4");
ba89f59ab825d4 include/asm-sparc/current.h David S. Miller 2007-11-16  19  #endif
^1da177e4c3f41 include/asm-sparc/current.h Linus Torvalds  2005-04-16  20
  
kernel test robot March 19, 2023, 2:16 a.m. UTC | #2
Hi Lorenzo,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on akpm-mm/mm-everything]
[also build test WARNING on linus/master v6.3-rc2 next-20230317]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Lorenzo-Stoakes/fs-proc-kcore-Avoid-bounce-buffer-for-ktext-data/20230319-082147
base:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
patch link:    https://lore.kernel.org/r/119871ea9507eac7be5d91db38acdb03981e049e.1679183626.git.lstoakes%40gmail.com
patch subject: [PATCH 4/4] mm: vmalloc: convert vread() to vread_iter()
config: sh-randconfig-r013-20230319 (https://download.01.org/0day-ci/archive/20230319/202303191017.vsaaDpyw-lkp@intel.com/config)
compiler: sh4-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/a28f374d35bd294a529fcba0b69c8b0e2b66fa6c
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Lorenzo-Stoakes/fs-proc-kcore-Avoid-bounce-buffer-for-ktext-data/20230319-082147
        git checkout a28f374d35bd294a529fcba0b69c8b0e2b66fa6c
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=sh olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=sh SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>
| Link: https://lore.kernel.org/oe-kbuild-all/202303191017.vsaaDpyw-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> mm/nommu.c:201:6: warning: no previous prototype for 'vread' [-Wmissing-prototypes]
     201 | long vread(char *buf, char *addr, unsigned long count)
         |      ^~~~~


vim +/vread +201 mm/nommu.c

^1da177e4c3f41 Linus Torvalds 2005-04-16  200  
^1da177e4c3f41 Linus Torvalds 2005-04-16 @201  long vread(char *buf, char *addr, unsigned long count)
^1da177e4c3f41 Linus Torvalds 2005-04-16  202  {
9bde916bc73255 Chen Gang      2013-07-03  203  	/* Don't allow overflow */
9bde916bc73255 Chen Gang      2013-07-03  204  	if ((unsigned long) buf + count < count)
9bde916bc73255 Chen Gang      2013-07-03  205  		count = -(unsigned long) buf;
9bde916bc73255 Chen Gang      2013-07-03  206  
^1da177e4c3f41 Linus Torvalds 2005-04-16  207  	memcpy(buf, addr, count);
^1da177e4c3f41 Linus Torvalds 2005-04-16  208  	return count;
^1da177e4c3f41 Linus Torvalds 2005-04-16  209  }
^1da177e4c3f41 Linus Torvalds 2005-04-16  210
  
Matthew Wilcox March 19, 2023, 2:50 a.m. UTC | #3
On Sun, Mar 19, 2023 at 12:20:12AM +0000, Lorenzo Stoakes wrote:
>  /* for /proc/kcore */
> -extern long vread(char *buf, char *addr, unsigned long count);
> +extern long vread_iter(char *addr, size_t count, struct iov_iter *iter);

I don't love the order of the arguments here.  Usually we follow
memcpy() and have (dst, src, len).  This sometimes gets a bit more
complex when either src or dst need two arguments, but that's not the
case here.
  
Lorenzo Stoakes March 19, 2023, 6:03 a.m. UTC | #4
On Sun, Mar 19, 2023 at 10:16:59AM +0800, kernel test robot wrote:
> Hi Lorenzo,
>
> Thank you for the patch! Perhaps something to improve:
>
> [auto build test WARNING on akpm-mm/mm-everything]
> [also build test WARNING on linus/master v6.3-rc2 next-20230317]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch#_base_tree_information]
>
> url:    https://github.com/intel-lab-lkp/linux/commits/Lorenzo-Stoakes/fs-proc-kcore-Avoid-bounce-buffer-for-ktext-data/20230319-082147
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
> patch link:    https://lore.kernel.org/r/119871ea9507eac7be5d91db38acdb03981e049e.1679183626.git.lstoakes%40gmail.com
> patch subject: [PATCH 4/4] mm: vmalloc: convert vread() to vread_iter()
> config: sh-randconfig-r013-20230319 (https://download.01.org/0day-ci/archive/20230319/202303191017.vsaaDpyw-lkp@intel.com/config)
> compiler: sh4-linux-gcc (GCC) 12.1.0
> reproduce (this is a W=1 build):
>         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>         chmod +x ~/bin/make.cross
>         # https://github.com/intel-lab-lkp/linux/commit/a28f374d35bd294a529fcba0b69c8b0e2b66fa6c
>         git remote add linux-review https://github.com/intel-lab-lkp/linux
>         git fetch --no-tags linux-review Lorenzo-Stoakes/fs-proc-kcore-Avoid-bounce-buffer-for-ktext-data/20230319-082147
>         git checkout a28f374d35bd294a529fcba0b69c8b0e2b66fa6c
>         # save the config file
>         mkdir build_dir && cp config build_dir/.config
>         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=sh olddefconfig
>         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=sh SHELL=/bin/bash
>
> If you fix the issue, kindly add following tag where applicable
> | Reported-by: kernel test robot <lkp@intel.com>
> | Link: https://lore.kernel.org/oe-kbuild-all/202303191017.vsaaDpyw-lkp@intel.com/
>
> All warnings (new ones prefixed by >>):
>
> >> mm/nommu.c:201:6: warning: no previous prototype for 'vread' [-Wmissing-prototypes]
>      201 | long vread(char *buf, char *addr, unsigned long count)
>          |      ^~~~~
>

Ah sorry, I forgot to update the nommu stub, will respin with a fix.
>
> vim +/vread +201 mm/nommu.c
>
> ^1da177e4c3f41 Linus Torvalds 2005-04-16  200
> ^1da177e4c3f41 Linus Torvalds 2005-04-16 @201  long vread(char *buf, char *addr, unsigned long count)
> ^1da177e4c3f41 Linus Torvalds 2005-04-16  202  {
> 9bde916bc73255 Chen Gang      2013-07-03  203  	/* Don't allow overflow */
> 9bde916bc73255 Chen Gang      2013-07-03  204  	if ((unsigned long) buf + count < count)
> 9bde916bc73255 Chen Gang      2013-07-03  205  		count = -(unsigned long) buf;
> 9bde916bc73255 Chen Gang      2013-07-03  206
> ^1da177e4c3f41 Linus Torvalds 2005-04-16  207  	memcpy(buf, addr, count);
> ^1da177e4c3f41 Linus Torvalds 2005-04-16  208  	return count;
> ^1da177e4c3f41 Linus Torvalds 2005-04-16  209  }
> ^1da177e4c3f41 Linus Torvalds 2005-04-16  210
>
> --
> 0-DAY CI Kernel Test Service
> https://github.com/intel/lkp-tests
  
Lorenzo Stoakes March 19, 2023, 6:08 a.m. UTC | #5
On Sun, Mar 19, 2023 at 09:46:03AM +0800, kernel test robot wrote:
> Hi Lorenzo,
>
> Thank you for the patch! Perhaps something to improve:
>
> [auto build test WARNING on akpm-mm/mm-everything]
> [also build test WARNING on linus/master v6.3-rc2 next-20230317]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch#_base_tree_information]
>
> url:    https://github.com/intel-lab-lkp/linux/commits/Lorenzo-Stoakes/fs-proc-kcore-Avoid-bounce-buffer-for-ktext-data/20230319-082147
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm.git mm-everything
> patch link:    https://lore.kernel.org/r/119871ea9507eac7be5d91db38acdb03981e049e.1679183626.git.lstoakes%40gmail.com
> patch subject: [PATCH 4/4] mm: vmalloc: convert vread() to vread_iter()
> config: sparc64-randconfig-r015-20230319 (https://download.01.org/0day-ci/archive/20230319/202303190922.Wk376onx-lkp@intel.com/config)
> compiler: sparc64-linux-gcc (GCC) 12.1.0
> reproduce (this is a W=1 build):
>         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>         chmod +x ~/bin/make.cross
>         # https://github.com/intel-lab-lkp/linux/commit/a28f374d35bd294a529fcba0b69c8b0e2b66fa6c
>         git remote add linux-review https://github.com/intel-lab-lkp/linux
>         git fetch --no-tags linux-review Lorenzo-Stoakes/fs-proc-kcore-Avoid-bounce-buffer-for-ktext-data/20230319-082147
>         git checkout a28f374d35bd294a529fcba0b69c8b0e2b66fa6c
>         # save the config file
>         mkdir build_dir && cp config build_dir/.config
>         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=sparc64 olddefconfig
>         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=sparc64 SHELL=/bin/bash arch/sparc/vdso/
>
> If you fix the issue, kindly add following tag where applicable
> | Reported-by: kernel test robot <lkp@intel.com>
> | Link: https://lore.kernel.org/oe-kbuild-all/202303190922.Wk376onx-lkp@intel.com/
>
> All warnings (new ones prefixed by >>):
>
>    In file included from include/linux/wait.h:11,
>                     from include/linux/swait.h:8,
>                     from include/linux/completion.h:12,
>                     from include/linux/mm_types.h:14,
>                     from include/linux/uio.h:10,
>                     from include/linux/vmalloc.h:12,
>                     from include/asm-generic/io.h:994,
>                     from arch/sparc/include/asm/io.h:22,
>                     from arch/sparc/vdso/vclock_gettime.c:18:
> >> arch/sparc/include/asm/current.h:18:30: warning: call-clobbered register used for global register variable
>       18 | register struct task_struct *current asm("g4");
>          |                              ^~~~~~~
>    arch/sparc/vdso/vclock_gettime.c:254:1: warning: no previous prototype for '__vdso_clock_gettime' [-Wmissing-prototypes]
>      254 | __vdso_clock_gettime(clockid_t clock, struct __kernel_old_timespec *ts)
>          | ^~~~~~~~~~~~~~~~~~~~
>    arch/sparc/vdso/vclock_gettime.c:282:1: warning: no previous prototype for '__vdso_clock_gettime_stick' [-Wmissing-prototypes]
>      282 | __vdso_clock_gettime_stick(clockid_t clock, struct __kernel_old_timespec *ts)
>          | ^~~~~~~~~~~~~~~~~~~~~~~~~~
>    arch/sparc/vdso/vclock_gettime.c:307:1: warning: no previous prototype for '__vdso_gettimeofday' [-Wmissing-prototypes]
>      307 | __vdso_gettimeofday(struct __kernel_old_timeval *tv, struct timezone *tz)
>          | ^~~~~~~~~~~~~~~~~~~
>    arch/sparc/vdso/vclock_gettime.c:343:1: warning: no previous prototype for '__vdso_gettimeofday_stick' [-Wmissing-prototypes]
>      343 | __vdso_gettimeofday_stick(struct __kernel_old_timeval *tv, struct timezone *tz)
>          | ^~~~~~~~~~~~~~~~~~~~~~~~~
>
>
> vim +18 arch/sparc/include/asm/current.h
>
> ^1da177e4c3f41 include/asm-sparc/current.h Linus Torvalds  2005-04-16  16
> ba89f59ab825d4 include/asm-sparc/current.h David S. Miller 2007-11-16  17  #ifdef CONFIG_SPARC64
> ba89f59ab825d4 include/asm-sparc/current.h David S. Miller 2007-11-16 @18  register struct task_struct *current asm("g4");
> ba89f59ab825d4 include/asm-sparc/current.h David S. Miller 2007-11-16  19  #endif
> ^1da177e4c3f41 include/asm-sparc/current.h Linus Torvalds  2005-04-16  20
>
> --
> 0-DAY CI Kernel Test Service
> https://github.com/intel/lkp-tests

This doesn't seem even vaguely related to this patchset, possibly my not
specifying that I am basing on mm-unstable may be a factor here.
  
Lorenzo Stoakes March 19, 2023, 6:16 a.m. UTC | #6
On Sun, Mar 19, 2023 at 02:50:56AM +0000, Matthew Wilcox wrote:
> On Sun, Mar 19, 2023 at 12:20:12AM +0000, Lorenzo Stoakes wrote:
> >  /* for /proc/kcore */
> > -extern long vread(char *buf, char *addr, unsigned long count);
> > +extern long vread_iter(char *addr, size_t count, struct iov_iter *iter);
>
> I don't love the order of the arguments here.  Usually we follow
> memcpy() and have (dst, src, len).  This sometimes gets a bit more
> complex when either src or dst need two arguments, but that's not the
> case here.

Indeed it's not delightful, I did this purely to mimic the order of
copy_to_iter() and friends which place iter last, however on second thoughts I
think placing iter first would be better here where we have the freedom to order
things more sensibly.

I'll respin with a fix.
  
David Laight March 19, 2023, 10:28 p.m. UTC | #7
From: Matthew Wilcox
> Sent: 19 March 2023 02:51
> 
> On Sun, Mar 19, 2023 at 12:20:12AM +0000, Lorenzo Stoakes wrote:
> >  /* for /proc/kcore */
> > -extern long vread(char *buf, char *addr, unsigned long count);
> > +extern long vread_iter(char *addr, size_t count, struct iov_iter *iter);
> 
> I don't love the order of the arguments here.  Usually we follow
> memcpy() and have (dst, src, len).  This sometimes gets a bit more
> complex when either src or dst need two arguments, but that's not the
> case here.

And, if 'addr' is the source (which Matthew's comment implies)
it ought to be 'const char *' (or probably even 'const void *').

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
  
Lorenzo Stoakes March 20, 2023, 8:30 a.m. UTC | #8
On Sun, Mar 19, 2023 at 10:28:12PM +0000, David Laight wrote:
> From: Matthew Wilcox
> > Sent: 19 March 2023 02:51
> >
> > On Sun, Mar 19, 2023 at 12:20:12AM +0000, Lorenzo Stoakes wrote:
> > >  /* for /proc/kcore */
> > > -extern long vread(char *buf, char *addr, unsigned long count);
> > > +extern long vread_iter(char *addr, size_t count, struct iov_iter *iter);
> >
> > I don't love the order of the arguments here.  Usually we follow
> > memcpy() and have (dst, src, len).  This sometimes gets a bit more
> > complex when either src or dst need two arguments, but that's not the
> > case here.
>
> And, if 'addr' is the source (which Matthew's comment implies)
> it ought to be 'const char *' (or probably even 'const void *').
>

Ack, I'll update on the next respin.

> 	David
>
> -
> Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
> Registration No: 1397386 (Wales)
>
  

Patch

diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
index 25e0eeb8d498..8a07f04c9203 100644
--- a/fs/proc/kcore.c
+++ b/fs/proc/kcore.c
@@ -307,13 +307,9 @@  static void append_kcore_note(char *notes, size_t *i, const char *name,
 	*i = ALIGN(*i + descsz, 4);
 }
 
-static ssize_t
-read_kcore_iter(struct kiocb *iocb, struct iov_iter *iter)
+static ssize_t read_kcore_iter(struct kiocb *iocb, struct iov_iter *iter)
 {
-	struct file *file = iocb->ki_filp;
-	char *buf = file->private_data;
 	loff_t *ppos = &iocb->ki_pos;
-
 	size_t phdrs_offset, notes_offset, data_offset;
 	size_t page_offline_frozen = 1;
 	size_t phdrs_len, notes_len;
@@ -507,9 +503,7 @@  read_kcore_iter(struct kiocb *iocb, struct iov_iter *iter)
 
 		switch (m->type) {
 		case KCORE_VMALLOC:
-			vread(buf, (char *)start, tsz);
-			/* we have to zero-fill user buffer even if no read */
-			if (copy_to_iter(buf, tsz, iter) != tsz) {
+			if (vread_iter((char *)start, tsz, iter) != tsz) {
 				ret = -EFAULT;
 				goto out;
 			}
@@ -582,10 +576,6 @@  static int open_kcore(struct inode *inode, struct file *filp)
 	if (ret)
 		return ret;
 
-	filp->private_data = kmalloc(PAGE_SIZE, GFP_KERNEL);
-	if (!filp->private_data)
-		return -ENOMEM;
-
 	if (kcore_need_update)
 		kcore_update_ram();
 	if (i_size_read(inode) != proc_root_kcore->size) {
@@ -596,16 +586,9 @@  static int open_kcore(struct inode *inode, struct file *filp)
 	return 0;
 }
 
-static int release_kcore(struct inode *inode, struct file *file)
-{
-	kfree(file->private_data);
-	return 0;
-}
-
 static const struct proc_ops kcore_proc_ops = {
 	.proc_read_iter	= read_kcore_iter,
 	.proc_open	= open_kcore,
-	.proc_release	= release_kcore,
 	.proc_lseek	= default_llseek,
 };
 
diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
index 69250efa03d1..f70ebdf21f22 100644
--- a/include/linux/vmalloc.h
+++ b/include/linux/vmalloc.h
@@ -9,6 +9,7 @@ 
 #include <asm/page.h>		/* pgprot_t */
 #include <linux/rbtree.h>
 #include <linux/overflow.h>
+#include <linux/uio.h>
 
 #include <asm/vmalloc.h>
 
@@ -251,7 +252,7 @@  static inline void set_vm_flush_reset_perms(void *addr)
 #endif
 
 /* for /proc/kcore */
-extern long vread(char *buf, char *addr, unsigned long count);
+extern long vread_iter(char *addr, size_t count, struct iov_iter *iter);
 
 /*
  *	Internals.  Don't use..
diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index c24b27664a97..3a32754266dc 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -37,7 +37,6 @@ 
 #include <linux/rbtree_augmented.h>
 #include <linux/overflow.h>
 #include <linux/pgtable.h>
-#include <linux/uaccess.h>
 #include <linux/hugetlb.h>
 #include <linux/sched/mm.h>
 #include <linux/rwsem.h>
@@ -3446,20 +3445,20 @@  EXPORT_SYMBOL(vmalloc_32_user);
  * small helper routine , copy contents to buf from addr.
  * If the page is not present, fill zero.
  */
-
-static int aligned_vread(char *buf, char *addr, unsigned long count)
+static void aligned_vread_iter(char *addr, size_t count,
+			       struct iov_iter *iter)
 {
-	struct page *p;
-	int copied = 0;
+	struct page *page;
 
-	while (count) {
+	while (count > 0) {
 		unsigned long offset, length;
+		size_t copied = 0;
 
 		offset = offset_in_page(addr);
 		length = PAGE_SIZE - offset;
 		if (length > count)
 			length = count;
-		p = vmalloc_to_page(addr);
+		page = vmalloc_to_page(addr);
 		/*
 		 * To do safe access to this _mapped_ area, we need
 		 * lock. But adding lock here means that we need to add
@@ -3467,23 +3466,24 @@  static int aligned_vread(char *buf, char *addr, unsigned long count)
 		 * interface, rarely used. Instead of that, we'll use
 		 * kmap() and get small overhead in this access function.
 		 */
-		if (p) {
+		if (page) {
 			/* We can expect USER0 is not used -- see vread() */
-			void *map = kmap_atomic(p);
-			memcpy(buf, map + offset, length);
-			kunmap_atomic(map);
-		} else
-			memset(buf, 0, length);
+			void *map = kmap_local_page(page);
+
+			copied = copy_to_iter(map + offset, length, iter);
+			kunmap_local(map);
+		}
+
+		if (copied < length)
+			iov_iter_zero(length - copied, iter);
 
 		addr += length;
-		buf += length;
-		copied += length;
 		count -= length;
 	}
-	return copied;
 }
 
-static void vmap_ram_vread(char *buf, char *addr, int count, unsigned long flags)
+static void vmap_ram_vread_iter(char *addr, int count, unsigned long flags,
+				struct iov_iter *iter)
 {
 	char *start;
 	struct vmap_block *vb;
@@ -3496,7 +3496,7 @@  static void vmap_ram_vread(char *buf, char *addr, int count, unsigned long flags
 	 * handle it here.
 	 */
 	if (!(flags & VMAP_BLOCK)) {
-		aligned_vread(buf, addr, count);
+		aligned_vread_iter(addr, count, iter);
 		return;
 	}
 
@@ -3517,22 +3517,24 @@  static void vmap_ram_vread(char *buf, char *addr, int count, unsigned long flags
 		if (!count)
 			break;
 		start = vmap_block_vaddr(vb->va->va_start, rs);
-		while (addr < start) {
+
+		if (addr < start) {
+			size_t to_zero = min_t(size_t, start - addr, count);
+
+			iov_iter_zero(to_zero, iter);
+			addr += to_zero;
+			count -= (int)to_zero;
 			if (count == 0)
 				goto unlock;
-			*buf = '\0';
-			buf++;
-			addr++;
-			count--;
 		}
+
 		/*it could start reading from the middle of used region*/
 		offset = offset_in_page(addr);
 		n = ((re - rs + 1) << PAGE_SHIFT) - offset;
 		if (n > count)
 			n = count;
-		aligned_vread(buf, start+offset, n);
+		aligned_vread_iter(start + offset, n, iter);
 
-		buf += n;
 		addr += n;
 		count -= n;
 	}
@@ -3541,15 +3543,15 @@  static void vmap_ram_vread(char *buf, char *addr, int count, unsigned long flags
 
 finished:
 	/* zero-fill the left dirty or free regions */
-	if (count)
-		memset(buf, 0, count);
+	if (count > 0)
+		iov_iter_zero(count, iter);
 }
 
 /**
- * vread() - read vmalloc area in a safe way.
- * @buf:     buffer for reading data
- * @addr:    vm address.
- * @count:   number of bytes to be read.
+ * vread_iter() - read vmalloc area in a safe way to an iterator.
+ * @addr:         vm address.
+ * @count:        number of bytes to be read.
+ * @iter:         the iterator to which data should be written.
  *
  * This function checks that addr is a valid vmalloc'ed area, and
  * copy data from that area to a given buffer. If the given memory range
@@ -3569,13 +3571,13 @@  static void vmap_ram_vread(char *buf, char *addr, int count, unsigned long flags
  * (same number as @count) or %0 if [addr...addr+count) doesn't
  * include any intersection with valid vmalloc area
  */
-long vread(char *buf, char *addr, unsigned long count)
+long vread_iter(char *addr, size_t count, struct iov_iter *iter)
 {
 	struct vmap_area *va;
 	struct vm_struct *vm;
-	char *vaddr, *buf_start = buf;
-	unsigned long buflen = count;
-	unsigned long n, size, flags;
+	char *vaddr;
+	size_t buflen = count;
+	size_t n, size, flags;
 
 	might_sleep();
 
@@ -3595,7 +3597,7 @@  long vread(char *buf, char *addr, unsigned long count)
 		goto finished;
 
 	list_for_each_entry_from(va, &vmap_area_list, list) {
-		if (!count)
+		if (count == 0)
 			break;
 
 		vm = va->vm;
@@ -3619,36 +3621,39 @@  long vread(char *buf, char *addr, unsigned long count)
 
 		if (addr >= vaddr + size)
 			continue;
-		while (addr < vaddr) {
+
+		if (addr < vaddr) {
+			size_t to_zero = min_t(size_t, vaddr - addr, count);
+
+			iov_iter_zero(to_zero, iter);
+			addr += to_zero;
+			count -= to_zero;
 			if (count == 0)
 				goto finished;
-			*buf = '\0';
-			buf++;
-			addr++;
-			count--;
 		}
+
 		n = vaddr + size - addr;
 		if (n > count)
 			n = count;
 
 		if (flags & VMAP_RAM)
-			vmap_ram_vread(buf, addr, n, flags);
+			vmap_ram_vread_iter(addr, n, flags, iter);
 		else if (!(vm->flags & VM_IOREMAP))
-			aligned_vread(buf, addr, n);
+			aligned_vread_iter(addr, n, iter);
 		else /* IOREMAP area is treated as memory hole */
-			memset(buf, 0, n);
-		buf += n;
+			iov_iter_zero(n, iter);
+
 		addr += n;
 		count -= n;
 	}
 finished:
 	up_read(&vmap_area_lock);
 
-	if (buf == buf_start)
+	if (count == buflen)
 		return 0;
 	/* zero-fill memory holes */
-	if (buf != buf_start + buflen)
-		memset(buf, 0, buflen - (buf - buf_start));
+	if (count > 0)
+		iov_iter_zero(count, iter);
 
 	return buflen;
 }