diff mbox series

MIPS: crash_dump.c: Simplify copy_oldmem_page()

Message ID 1612516899-31285-1-git-send-email-tangyouling@loongson.cn (mailing list archive)
State Superseded
Headers show
Series MIPS: crash_dump.c: Simplify copy_oldmem_page() | expand

Commit Message

Youling Tang Feb. 5, 2021, 9:21 a.m. UTC
Replace kmap_atomic_pfn() with kmap_local_pfn() which is preemptible and
can take page faults.

Remove the indirection of the dump page and the related cruft which is not
longer required.

Remove unused or redundant header files.

Signed-off-by: Youling Tang <tangyouling@loongson.cn>
---
 arch/mips/kernel/crash_dump.c | 42 ++++++------------------------------------
 1 file changed, 6 insertions(+), 36 deletions(-)

Comments

kernel test robot Feb. 5, 2021, 11:29 a.m. UTC | #1
Hi Youling,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v5.11-rc6 next-20210125]
[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]

url:    https://github.com/0day-ci/linux/commits/Youling-Tang/MIPS-crash_dump-c-Simplify-copy_oldmem_page/20210205-174220
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 61556703b610a104de324e4f061dc6cf7b218b46
config: mips-allyesconfig (attached as .config)
compiler: mips-linux-gcc (GCC) 9.3.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/0day-ci/linux/commit/b784382bee7f0a7c02539598bfb477bf10f16c85
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Youling-Tang/MIPS-crash_dump-c-Simplify-copy_oldmem_page/20210205-174220
        git checkout b784382bee7f0a7c02539598bfb477bf10f16c85
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=mips 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> arch/mips/kernel/crash_dump.c:17:9: warning: no previous prototype for 'copy_oldmem_page' [-Wmissing-prototypes]
      17 | ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
         |         ^~~~~~~~~~~~~~~~


vim +/copy_oldmem_page +17 arch/mips/kernel/crash_dump.c

7aa1c8f47e7e79 Ralf Baechle 2012-10-11   3  
7aa1c8f47e7e79 Ralf Baechle 2012-10-11   4  /**
7aa1c8f47e7e79 Ralf Baechle 2012-10-11   5   * copy_oldmem_page - copy one page from "oldmem"
7aa1c8f47e7e79 Ralf Baechle 2012-10-11   6   * @pfn: page frame number to be copied
7aa1c8f47e7e79 Ralf Baechle 2012-10-11   7   * @buf: target memory address for the copy; this can be in kernel address
7aa1c8f47e7e79 Ralf Baechle 2012-10-11   8   *	space or user address space (see @userbuf)
7aa1c8f47e7e79 Ralf Baechle 2012-10-11   9   * @csize: number of bytes to copy
7aa1c8f47e7e79 Ralf Baechle 2012-10-11  10   * @offset: offset in bytes into the page (based on pfn) to begin the copy
7aa1c8f47e7e79 Ralf Baechle 2012-10-11  11   * @userbuf: if set, @buf is in user address space, use copy_to_user(),
7aa1c8f47e7e79 Ralf Baechle 2012-10-11  12   *	otherwise @buf is in kernel address space, use memcpy().
7aa1c8f47e7e79 Ralf Baechle 2012-10-11  13   *
7aa1c8f47e7e79 Ralf Baechle 2012-10-11  14   * Copy a page from "oldmem". For this page, there is no pte mapped
7aa1c8f47e7e79 Ralf Baechle 2012-10-11  15   * in the current kernel.
7aa1c8f47e7e79 Ralf Baechle 2012-10-11  16   */
7aa1c8f47e7e79 Ralf Baechle 2012-10-11 @17  ssize_t copy_oldmem_page(unsigned long pfn, char *buf,

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
kernel test robot Feb. 5, 2021, 10:39 p.m. UTC | #2
Hi Youling,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v5.11-rc6 next-20210125]
[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]

url:    https://github.com/0day-ci/linux/commits/Youling-Tang/MIPS-crash_dump-c-Simplify-copy_oldmem_page/20210205-174220
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 61556703b610a104de324e4f061dc6cf7b218b46
config: mips-randconfig-r035-20210205 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project c9439ca36342fb6013187d0a69aef92736951476)
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
        # install mips cross compiling tool for clang build
        # apt-get install binutils-mips-linux-gnu
        # https://github.com/0day-ci/linux/commit/b784382bee7f0a7c02539598bfb477bf10f16c85
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Youling-Tang/MIPS-crash_dump-c-Simplify-copy_oldmem_page/20210205-174220
        git checkout b784382bee7f0a7c02539598bfb477bf10f16c85
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=mips 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> arch/mips/kernel/crash_dump.c:17:9: warning: no previous prototype for function 'copy_oldmem_page' [-Wmissing-prototypes]
   ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
           ^
   arch/mips/kernel/crash_dump.c:17:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
   ^
   static 
   1 warning generated.


vim +/copy_oldmem_page +17 arch/mips/kernel/crash_dump.c

7aa1c8f47e7e79 Ralf Baechle 2012-10-11   3  
7aa1c8f47e7e79 Ralf Baechle 2012-10-11   4  /**
7aa1c8f47e7e79 Ralf Baechle 2012-10-11   5   * copy_oldmem_page - copy one page from "oldmem"
7aa1c8f47e7e79 Ralf Baechle 2012-10-11   6   * @pfn: page frame number to be copied
7aa1c8f47e7e79 Ralf Baechle 2012-10-11   7   * @buf: target memory address for the copy; this can be in kernel address
7aa1c8f47e7e79 Ralf Baechle 2012-10-11   8   *	space or user address space (see @userbuf)
7aa1c8f47e7e79 Ralf Baechle 2012-10-11   9   * @csize: number of bytes to copy
7aa1c8f47e7e79 Ralf Baechle 2012-10-11  10   * @offset: offset in bytes into the page (based on pfn) to begin the copy
7aa1c8f47e7e79 Ralf Baechle 2012-10-11  11   * @userbuf: if set, @buf is in user address space, use copy_to_user(),
7aa1c8f47e7e79 Ralf Baechle 2012-10-11  12   *	otherwise @buf is in kernel address space, use memcpy().
7aa1c8f47e7e79 Ralf Baechle 2012-10-11  13   *
7aa1c8f47e7e79 Ralf Baechle 2012-10-11  14   * Copy a page from "oldmem". For this page, there is no pte mapped
7aa1c8f47e7e79 Ralf Baechle 2012-10-11  15   * in the current kernel.
7aa1c8f47e7e79 Ralf Baechle 2012-10-11  16   */
7aa1c8f47e7e79 Ralf Baechle 2012-10-11 @17  ssize_t copy_oldmem_page(unsigned long pfn, char *buf,

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/arch/mips/kernel/crash_dump.c b/arch/mips/kernel/crash_dump.c
index 01b2bd9..f2eb91c 100644
--- a/arch/mips/kernel/crash_dump.c
+++ b/arch/mips/kernel/crash_dump.c
@@ -1,11 +1,5 @@ 
 // SPDX-License-Identifier: GPL-2.0
 #include <linux/highmem.h>
-#include <linux/memblock.h>
-#include <linux/crash_dump.h>
-#include <linux/uaccess.h>
-#include <linux/slab.h>
-
-static void *kdump_buf_page;
 
 /**
  * copy_oldmem_page - copy one page from "oldmem"
@@ -19,10 +13,6 @@  static void *kdump_buf_page;
  *
  * Copy a page from "oldmem". For this page, there is no pte mapped
  * in the current kernel.
- *
- * Calling copy_to_user() in atomic context is not desirable. Hence first
- * copying the data to a pre-allocated kernel page and then copying to user
- * space in non-atomic context.
  */
 ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
 			 size_t csize, unsigned long offset, int userbuf)
@@ -32,36 +22,16 @@  ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
 	if (!csize)
 		return 0;
 
-	vaddr = kmap_atomic_pfn(pfn);
+	vaddr = kmap_local_pfn(pfn);
 
 	if (!userbuf) {
-		memcpy(buf, (vaddr + offset), csize);
-		kunmap_atomic(vaddr);
+		memcpy(buf, vaddr + offset, csize);
 	} else {
-		if (!kdump_buf_page) {
-			pr_warn("Kdump: Kdump buffer page not allocated\n");
-
-			return -EFAULT;
-		}
-		copy_page(kdump_buf_page, vaddr);
-		kunmap_atomic(vaddr);
-		if (copy_to_user(buf, (kdump_buf_page + offset), csize))
-			return -EFAULT;
+		if (copy_to_user(buf, vaddr + offset, csize))
+			csize = -EFAULT;
 	}
 
-	return csize;
-}
-
-static int __init kdump_buf_page_init(void)
-{
-	int ret = 0;
+	kunmap_local(vaddr);
 
-	kdump_buf_page = kmalloc(PAGE_SIZE, GFP_KERNEL);
-	if (!kdump_buf_page) {
-		pr_warn("Kdump: Failed to allocate kdump buffer page\n");
-		ret = -ENOMEM;
-	}
-
-	return ret;
+	return csize;
 }
-arch_initcall(kdump_buf_page_init);