From patchwork Fri Dec 3 10:42:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Daniel Kachhap X-Patchwork-Id: 12654761 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24059C433F5 for ; Fri, 3 Dec 2021 10:42:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351769AbhLCKqQ (ORCPT ); Fri, 3 Dec 2021 05:46:16 -0500 Received: from foss.arm.com ([217.140.110.172]:46914 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351767AbhLCKqP (ORCPT ); Fri, 3 Dec 2021 05:46:15 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0A2021435; Fri, 3 Dec 2021 02:42:52 -0800 (PST) Received: from a077416.arm.com (unknown [10.163.33.180]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 01A703F5A1; Fri, 3 Dec 2021 02:42:46 -0800 (PST) From: Amit Daniel Kachhap To: linux-kernel@vger.kernel.org Cc: Christoph Hellwig , Vincenzo Frascino , Kevin Brodsky , linux-fsdevel , kexec , Amit Daniel Kachhap , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Young , Baoquan He , Vivek Goyal , x86 Subject: [RFC PATCH 01/14] fs/proc/vmcore: Update read_from_oldmem() for user pointer Date: Fri, 3 Dec 2021 16:12:18 +0530 Message-Id: <20211203104231.17597-2-amit.kachhap@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211203104231.17597-1-amit.kachhap@arm.com> References: <20211203104231.17597-1-amit.kachhap@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The exported interface read_from_oldmem() passes user pointer without __user annotation and does unnecessary user/kernel pointer conversions during the pointer propagation. Hence it is modified to have a new parameter for user pointer. Also a helper macro read_from_oldmem_to_kernel is added for clear readability from callsite when calling read_from_oldmem() for copying to kernel buffer. There are several internal functions used here such as read_vmcore(), __read_vmcore(), copy_to() and vmcoredd_copy_dumps() which are re-structured to avoid the unnecessary user/kernel pointer conversions. x86_64 crash dump is also modified to use this new interface. No functionality change intended. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Young Cc: Baoquan He Cc: Vivek Goyal Cc: x86 Cc: kexec Cc: linux-fsdevel Signed-off-by: Amit Daniel Kachhap --- arch/x86/kernel/crash_dump_64.c | 4 +- fs/proc/vmcore.c | 88 +++++++++++++++++++-------------- include/linux/crash_dump.h | 12 +++-- 3 files changed, 60 insertions(+), 44 deletions(-) diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c index a7f617a3981d..6433513ef43a 100644 --- a/arch/x86/kernel/crash_dump_64.c +++ b/arch/x86/kernel/crash_dump_64.c @@ -74,6 +74,6 @@ ssize_t copy_oldmem_page_encrypted(unsigned long pfn, char *buf, size_t csize, ssize_t elfcorehdr_read(char *buf, size_t count, u64 *ppos) { - return read_from_oldmem(buf, count, ppos, 0, - cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)); + return read_from_oldmem_to_kernel(buf, count, ppos, + cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)); } diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c index 509f85148fee..39b4353bd37c 100644 --- a/fs/proc/vmcore.c +++ b/fs/proc/vmcore.c @@ -70,6 +70,14 @@ static bool vmcore_cb_unstable; /* Whether the vmcore has been opened once. */ static bool vmcore_opened; +#define ptr_add(utarget, ktarget, size) \ +({ \ + if (utarget) \ + utarget += size; \ + else \ + ktarget += size; \ +}) + void register_vmcore_cb(struct vmcore_cb *cb) { down_write(&vmcore_cb_rwsem); @@ -132,9 +140,8 @@ static int open_vmcore(struct inode *inode, struct file *file) } /* Reads a page from the oldmem device from given offset. */ -ssize_t read_from_oldmem(char *buf, size_t count, - u64 *ppos, int userbuf, - bool encrypted) +ssize_t read_from_oldmem(char __user *ubuf, char *kbuf, size_t count, + u64 *ppos, bool encrypted) { unsigned long pfn, offset; size_t nr_bytes; @@ -156,19 +163,27 @@ ssize_t read_from_oldmem(char *buf, size_t count, /* If pfn is not ram, return zeros for sparse dump files */ if (!pfn_is_ram(pfn)) { tmp = 0; - if (!userbuf) - memset(buf, 0, nr_bytes); - else if (clear_user(buf, nr_bytes)) + if (kbuf) + memset(kbuf, 0, nr_bytes); + else if (clear_user(ubuf, nr_bytes)) tmp = -EFAULT; } else { - if (encrypted) - tmp = copy_oldmem_page_encrypted(pfn, buf, + if (encrypted && ubuf) + tmp = copy_oldmem_page_encrypted(pfn, + (__force char *)ubuf, + nr_bytes, + offset, 1); + else if (encrypted && kbuf) + tmp = copy_oldmem_page_encrypted(pfn, + kbuf, nr_bytes, - offset, - userbuf); + offset, 0); + else if (ubuf) + tmp = copy_oldmem_page(pfn, (__force char *)ubuf, + nr_bytes, offset, 1); else - tmp = copy_oldmem_page(pfn, buf, nr_bytes, - offset, userbuf); + tmp = copy_oldmem_page(pfn, kbuf, nr_bytes, + offset, 0); } if (tmp < 0) { up_read(&vmcore_cb_rwsem); @@ -177,7 +192,7 @@ ssize_t read_from_oldmem(char *buf, size_t count, *ppos += nr_bytes; count -= nr_bytes; - buf += nr_bytes; + ptr_add(ubuf, kbuf, nr_bytes); read += nr_bytes; ++pfn; offset = 0; @@ -206,7 +221,7 @@ void __weak elfcorehdr_free(unsigned long long addr) */ ssize_t __weak elfcorehdr_read(char *buf, size_t count, u64 *ppos) { - return read_from_oldmem(buf, count, ppos, 0, false); + return read_from_oldmem_to_kernel(buf, count, ppos, false); } /* @@ -214,7 +229,7 @@ ssize_t __weak elfcorehdr_read(char *buf, size_t count, u64 *ppos) */ ssize_t __weak elfcorehdr_read_notes(char *buf, size_t count, u64 *ppos) { - return read_from_oldmem(buf, count, ppos, 0, cc_platform_has(CC_ATTR_MEM_ENCRYPT)); + return read_from_oldmem_to_kernel(buf, count, ppos, cc_platform_has(CC_ATTR_MEM_ENCRYPT)); } /* @@ -239,21 +254,21 @@ copy_oldmem_page_encrypted(unsigned long pfn, char *buf, size_t csize, } /* - * Copy to either kernel or user space + * Copy to either kernel or user space buffer */ -static int copy_to(void *target, void *src, size_t size, int userbuf) +static int copy_to(void __user *utarget, void *ktarget, void *src, size_t size) { - if (userbuf) { - if (copy_to_user((char __user *) target, src, size)) + if (utarget) { + if (copy_to_user(utarget, src, size)) return -EFAULT; } else { - memcpy(target, src, size); + memcpy(ktarget, src, size); } return 0; } #ifdef CONFIG_PROC_VMCORE_DEVICE_DUMP -static int vmcoredd_copy_dumps(void *dst, u64 start, size_t size, int userbuf) +static int vmcoredd_copy_dumps(void __user *udst, void *kdst, u64 start, size_t size) { struct vmcoredd_node *dump; u64 offset = 0; @@ -266,15 +281,14 @@ static int vmcoredd_copy_dumps(void *dst, u64 start, size_t size, int userbuf) if (start < offset + dump->size) { tsz = min(offset + (u64)dump->size - start, (u64)size); buf = dump->buf + start - offset; - if (copy_to(dst, buf, tsz, userbuf)) { + if (copy_to(udst, kdst, buf, tsz)) { ret = -EFAULT; goto out_unlock; } size -= tsz; start += tsz; - dst += tsz; - + ptr_add(udst, kdst, tsz); /* Leave now if buffer filled already */ if (!size) goto out_unlock; @@ -329,8 +343,8 @@ static int vmcoredd_mmap_dumps(struct vm_area_struct *vma, unsigned long dst, /* Read from the ELF header and then the crash dump. On error, negative value is * returned otherwise number of bytes read are returned. */ -static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos, - int userbuf) +static ssize_t __read_vmcore(char __user *ubuffer, char *kbuffer, size_t buflen, + loff_t *fpos) { ssize_t acc = 0, tmp; size_t tsz; @@ -347,11 +361,11 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos, /* Read ELF core header */ if (*fpos < elfcorebuf_sz) { tsz = min(elfcorebuf_sz - (size_t)*fpos, buflen); - if (copy_to(buffer, elfcorebuf + *fpos, tsz, userbuf)) + if (copy_to(ubuffer, kbuffer, elfcorebuf + *fpos, tsz)) return -EFAULT; buflen -= tsz; *fpos += tsz; - buffer += tsz; + ptr_add(ubuffer, kbuffer, tsz); acc += tsz; /* leave now if filled buffer already */ @@ -378,12 +392,12 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos, tsz = min(elfcorebuf_sz + vmcoredd_orig_sz - (size_t)*fpos, buflen); start = *fpos - elfcorebuf_sz; - if (vmcoredd_copy_dumps(buffer, start, tsz, userbuf)) + if (vmcoredd_copy_dumps(ubuffer, kbuffer, start, tsz)) return -EFAULT; buflen -= tsz; *fpos += tsz; - buffer += tsz; + ptr_add(ubuffer, kbuffer, tsz); acc += tsz; /* leave now if filled buffer already */ @@ -395,12 +409,12 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos, /* Read remaining elf notes */ tsz = min(elfcorebuf_sz + elfnotes_sz - (size_t)*fpos, buflen); kaddr = elfnotes_buf + *fpos - elfcorebuf_sz - vmcoredd_orig_sz; - if (copy_to(buffer, kaddr, tsz, userbuf)) + if (copy_to(ubuffer, kbuffer, kaddr, tsz)) return -EFAULT; buflen -= tsz; *fpos += tsz; - buffer += tsz; + ptr_add(ubuffer, kbuffer, tsz); acc += tsz; /* leave now if filled buffer already */ @@ -414,13 +428,13 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos, m->offset + m->size - *fpos, buflen); start = m->paddr + *fpos - m->offset; - tmp = read_from_oldmem(buffer, tsz, &start, - userbuf, cc_platform_has(CC_ATTR_MEM_ENCRYPT)); + tmp = read_from_oldmem(ubuffer, kbuffer, tsz, &start, + cc_platform_has(CC_ATTR_MEM_ENCRYPT)); if (tmp < 0) return tmp; buflen -= tsz; *fpos += tsz; - buffer += tsz; + ptr_add(ubuffer, kbuffer, tsz); acc += tsz; /* leave now if filled buffer already */ @@ -435,7 +449,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos, static ssize_t read_vmcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos) { - return __read_vmcore((__force char *) buffer, buflen, fpos, 1); + return __read_vmcore(buffer, NULL, buflen, fpos); } /* @@ -461,7 +475,7 @@ static vm_fault_t mmap_vmcore_fault(struct vm_fault *vmf) if (!PageUptodate(page)) { offset = (loff_t) index << PAGE_SHIFT; buf = __va((page_to_pfn(page) << PAGE_SHIFT)); - rc = __read_vmcore(buf, PAGE_SIZE, &offset, 0); + rc = __read_vmcore(NULL, buf, PAGE_SIZE, &offset); if (rc < 0) { unlock_page(page); put_page(page); diff --git a/include/linux/crash_dump.h b/include/linux/crash_dump.h index 620821549b23..eb0ed423ccc8 100644 --- a/include/linux/crash_dump.h +++ b/include/linux/crash_dump.h @@ -135,16 +135,18 @@ static inline int vmcore_add_device_dump(struct vmcoredd_data *data) #endif /* CONFIG_PROC_VMCORE_DEVICE_DUMP */ #ifdef CONFIG_PROC_VMCORE -ssize_t read_from_oldmem(char *buf, size_t count, - u64 *ppos, int userbuf, - bool encrypted); +ssize_t read_from_oldmem(char __user *ubuf, char *kbuf, size_t count, + u64 *ppos, bool encrypted); #else -static inline ssize_t read_from_oldmem(char *buf, size_t count, - u64 *ppos, int userbuf, +static inline ssize_t read_from_oldmem(char __user *ubuf, char *kbuf, + size_t count, u64 *ppos, bool encrypted) { return -EOPNOTSUPP; } #endif /* CONFIG_PROC_VMCORE */ +#define read_from_oldmem_to_kernel(buf, count, ppos, encrypted) \ + read_from_oldmem(NULL, buf, count, ppos, encrypted) + #endif /* LINUX_CRASHDUMP_H */ From patchwork Fri Dec 3 10:42:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Daniel Kachhap X-Patchwork-Id: 12654763 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CCB78C433EF for ; Fri, 3 Dec 2021 10:42:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351827AbhLCKqW (ORCPT ); Fri, 3 Dec 2021 05:46:22 -0500 Received: from foss.arm.com ([217.140.110.172]:46934 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351858AbhLCKqV (ORCPT ); Fri, 3 Dec 2021 05:46:21 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8B7B81477; Fri, 3 Dec 2021 02:42:57 -0800 (PST) Received: from a077416.arm.com (unknown [10.163.33.180]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 9C1773F5A1; Fri, 3 Dec 2021 02:42:52 -0800 (PST) From: Amit Daniel Kachhap To: linux-kernel@vger.kernel.org Cc: Christoph Hellwig , Vincenzo Frascino , Kevin Brodsky , linux-fsdevel , kexec , Amit Daniel Kachhap , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Young , Baoquan He , Vivek Goyal , x86 Subject: [RFC PATCH 02/14] fs/proc/vmcore: Update copy_oldmem_page_encrypted() for user buffer Date: Fri, 3 Dec 2021 16:12:19 +0530 Message-Id: <20211203104231.17597-3-amit.kachhap@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211203104231.17597-1-amit.kachhap@arm.com> References: <20211203104231.17597-1-amit.kachhap@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The exported interface copy_oldmem_page_encrypted() passes user pointer without __user annotation and does unnecessary user/kernel pointer conversions during the pointer propagation. Hence it is modified to have a new parameter for user pointer. The other similar interface copy_oldmem_page() will be updated in the subsequent patches. x86_64 crash dump is also modified to use this modified interface. No functionality change intended. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Young Cc: Baoquan He Cc: Vivek Goyal Cc: x86 Cc: kexec Cc: linux-fsdevel Signed-off-by: Amit Daniel Kachhap --- arch/x86/kernel/crash_dump_64.c | 12 +++++++++--- fs/proc/vmcore.c | 24 +++++++++++------------- include/linux/crash_dump.h | 6 +++--- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c index 6433513ef43a..99cd505628fa 100644 --- a/arch/x86/kernel/crash_dump_64.c +++ b/arch/x86/kernel/crash_dump_64.c @@ -66,10 +66,16 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf, size_t csize, * memory with the encryption mask set to accommodate kdump on SME-enabled * machines. */ -ssize_t copy_oldmem_page_encrypted(unsigned long pfn, char *buf, size_t csize, - unsigned long offset, int userbuf) +ssize_t copy_oldmem_page_encrypted(unsigned long pfn, char __user *ubuf, + char *kbuf, size_t csize, + unsigned long offset) { - return __copy_oldmem_page(pfn, buf, csize, offset, userbuf, true); + if (ubuf) + return __copy_oldmem_page(pfn, (__force char *)ubuf, csize, + offset, 1, true); + else + return __copy_oldmem_page(pfn, kbuf, csize, + offset, 0, true); } ssize_t elfcorehdr_read(char *buf, size_t count, u64 *ppos) diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c index 39b4353bd37c..fa4492ef6124 100644 --- a/fs/proc/vmcore.c +++ b/fs/proc/vmcore.c @@ -168,16 +168,10 @@ ssize_t read_from_oldmem(char __user *ubuf, char *kbuf, size_t count, else if (clear_user(ubuf, nr_bytes)) tmp = -EFAULT; } else { - if (encrypted && ubuf) - tmp = copy_oldmem_page_encrypted(pfn, - (__force char *)ubuf, - nr_bytes, - offset, 1); - else if (encrypted && kbuf) - tmp = copy_oldmem_page_encrypted(pfn, - kbuf, - nr_bytes, - offset, 0); + if (encrypted) + tmp = copy_oldmem_page_encrypted(pfn, ubuf, + kbuf, nr_bytes, + offset); else if (ubuf) tmp = copy_oldmem_page(pfn, (__force char *)ubuf, nr_bytes, offset, 1); @@ -247,10 +241,14 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma, * Architectures which support memory encryption override this. */ ssize_t __weak -copy_oldmem_page_encrypted(unsigned long pfn, char *buf, size_t csize, - unsigned long offset, int userbuf) +copy_oldmem_page_encrypted(unsigned long pfn, char __user *ubuf, char *kbuf, + size_t csize, unsigned long offset) { - return copy_oldmem_page(pfn, buf, csize, offset, userbuf); + if (ubuf) + return copy_oldmem_page(pfn, (__force char *)ubuf, csize, + offset, 1); + else + return copy_oldmem_page(pfn, kbuf, csize, offset, 0); } /* diff --git a/include/linux/crash_dump.h b/include/linux/crash_dump.h index eb0ed423ccc8..36a7f08f4ad2 100644 --- a/include/linux/crash_dump.h +++ b/include/linux/crash_dump.h @@ -26,9 +26,9 @@ extern int remap_oldmem_pfn_range(struct vm_area_struct *vma, extern ssize_t copy_oldmem_page(unsigned long, char *, size_t, unsigned long, int); -extern ssize_t copy_oldmem_page_encrypted(unsigned long pfn, char *buf, - size_t csize, unsigned long offset, - int userbuf); +extern ssize_t copy_oldmem_page_encrypted(unsigned long pfn, + char __user *ubuf, char *kbuf, + size_t csize, unsigned long offset); void vmcore_cleanup(void); From patchwork Fri Dec 3 10:42:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Daniel Kachhap X-Patchwork-Id: 12654765 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CCBF5C433F5 for ; Fri, 3 Dec 2021 10:43:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351889AbhLCKq1 (ORCPT ); Fri, 3 Dec 2021 05:46:27 -0500 Received: from foss.arm.com ([217.140.110.172]:46954 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351903AbhLCKqZ (ORCPT ); Fri, 3 Dec 2021 05:46:25 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D4BB714BF; Fri, 3 Dec 2021 02:43:01 -0800 (PST) Received: from a077416.arm.com (unknown [10.163.33.180]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 292733F5A1; Fri, 3 Dec 2021 02:42:57 -0800 (PST) From: Amit Daniel Kachhap To: linux-kernel@vger.kernel.org Cc: Christoph Hellwig , Vincenzo Frascino , Kevin Brodsky , linux-fsdevel , kexec , Amit Daniel Kachhap , Dave Young , Baoquan He , Vivek Goyal Subject: [RFC PATCH 03/14] fs/proc/vmcore: Update copy_oldmem_page() for user buffer Date: Fri, 3 Dec 2021 16:12:20 +0530 Message-Id: <20211203104231.17597-4-amit.kachhap@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211203104231.17597-1-amit.kachhap@arm.com> References: <20211203104231.17597-1-amit.kachhap@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The exported interface copy_oldmem_page passes user pointer without __user annotation and does unnecessary user/kernel pointer conversions during the pointer propagation. Hence it is modified to have a new parameter for user pointer. However instead of updating it directly a new interface copy_oldmem_page_buf() is added as copy_oldmem_page() is used across different archs. This old interface copy_oldmem_page() will be deleted after all the archs are modified to use the new interface. The weak implementation of both copy_oldmem_page() and copy_oldmem_page_buf() are added temporarily to keep the kernel building for the subsequent patches. As a consequence, crash dump is temporarily broken for the archs till the patch where it implements its own copy_oldmem_page_buf(). Cc: Dave Young Cc: Baoquan He Cc: Vivek Goyal Cc: kexec Cc: linux-fsdevel Signed-off-by: Amit Daniel Kachhap --- fs/proc/vmcore.c | 27 +++++++++++++++++---------- include/linux/crash_dump.h | 3 +++ 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c index fa4492ef6124..d01b85c043dd 100644 --- a/fs/proc/vmcore.c +++ b/fs/proc/vmcore.c @@ -172,12 +172,9 @@ ssize_t read_from_oldmem(char __user *ubuf, char *kbuf, size_t count, tmp = copy_oldmem_page_encrypted(pfn, ubuf, kbuf, nr_bytes, offset); - else if (ubuf) - tmp = copy_oldmem_page(pfn, (__force char *)ubuf, - nr_bytes, offset, 1); else - tmp = copy_oldmem_page(pfn, kbuf, nr_bytes, - offset, 0); + tmp = copy_oldmem_page_buf(pfn, ubuf, kbuf, + nr_bytes, offset); } if (tmp < 0) { up_read(&vmcore_cb_rwsem); @@ -244,11 +241,21 @@ ssize_t __weak copy_oldmem_page_encrypted(unsigned long pfn, char __user *ubuf, char *kbuf, size_t csize, unsigned long offset) { - if (ubuf) - return copy_oldmem_page(pfn, (__force char *)ubuf, csize, - offset, 1); - else - return copy_oldmem_page(pfn, kbuf, csize, offset, 0); + return copy_oldmem_page_buf(pfn, ubuf, kbuf, csize, offset); +} + +ssize_t __weak +copy_oldmem_page_buf(unsigned long pfn, char __user *ubuf, char *kbuf, + size_t csize, unsigned long offset) +{ + return -EOPNOTSUPP; +} + +ssize_t __weak +copy_oldmem_page(unsigned long pfn, char *ubuf, size_t csize, + unsigned long offset, int userbuf) +{ + return -EOPNOTSUPP; } /* diff --git a/include/linux/crash_dump.h b/include/linux/crash_dump.h index 36a7f08f4ad2..725c4e053ecf 100644 --- a/include/linux/crash_dump.h +++ b/include/linux/crash_dump.h @@ -26,6 +26,9 @@ extern int remap_oldmem_pfn_range(struct vm_area_struct *vma, extern ssize_t copy_oldmem_page(unsigned long, char *, size_t, unsigned long, int); +extern ssize_t copy_oldmem_page_buf(unsigned long pfn, char __user *ubuf, + char *kbuf, size_t csize, + unsigned long offset); extern ssize_t copy_oldmem_page_encrypted(unsigned long pfn, char __user *ubuf, char *kbuf, size_t csize, unsigned long offset); From patchwork Fri Dec 3 10:42:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Daniel Kachhap X-Patchwork-Id: 12654767 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0EDEFC433EF for ; Fri, 3 Dec 2021 10:43:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379965AbhLCKqc (ORCPT ); Fri, 3 Dec 2021 05:46:32 -0500 Received: from foss.arm.com ([217.140.110.172]:46968 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380014AbhLCKqa (ORCPT ); Fri, 3 Dec 2021 05:46:30 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C0233152B; Fri, 3 Dec 2021 02:43:06 -0800 (PST) Received: from a077416.arm.com (unknown [10.163.33.180]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6DF903F5A1; Fri, 3 Dec 2021 02:43:02 -0800 (PST) From: Amit Daniel Kachhap To: linux-kernel@vger.kernel.org Cc: Christoph Hellwig , Vincenzo Frascino , Kevin Brodsky , linux-fsdevel , kexec , Amit Daniel Kachhap , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86 Subject: [RFC PATCH 04/14] x86/crash_dump_64: Use the new interface copy_oldmem_page_buf Date: Fri, 3 Dec 2021 16:12:21 +0530 Message-Id: <20211203104231.17597-5-amit.kachhap@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211203104231.17597-1-amit.kachhap@arm.com> References: <20211203104231.17597-1-amit.kachhap@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The current interface copy_oldmem_page() passes user pointer without __user annotation and hence does unnecessary user/kernel pointer conversions during its implementation. Implement the interface copy_oldmem_page_buf() to avoid this issue. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: x86 Signed-off-by: Amit Daniel Kachhap --- arch/x86/kernel/crash_dump_64.c | 44 +++++++++++++++------------------ 1 file changed, 20 insertions(+), 24 deletions(-) diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c index 99cd505628fa..7a6fa797260f 100644 --- a/arch/x86/kernel/crash_dump_64.c +++ b/arch/x86/kernel/crash_dump_64.c @@ -12,9 +12,9 @@ #include #include -static ssize_t __copy_oldmem_page(unsigned long pfn, char *buf, size_t csize, - unsigned long offset, int userbuf, - bool encrypted) +static ssize_t __copy_oldmem_page(unsigned long pfn, char __user *ubuf, + char *kbuf, size_t csize, + unsigned long offset, bool encrypted) { void *vaddr; @@ -29,13 +29,13 @@ static ssize_t __copy_oldmem_page(unsigned long pfn, char *buf, size_t csize, if (!vaddr) return -ENOMEM; - if (userbuf) { - if (copy_to_user((void __user *)buf, vaddr + offset, csize)) { + if (ubuf) { + if (copy_to_user(ubuf, vaddr + offset, csize)) { iounmap((void __iomem *)vaddr); return -EFAULT; } } else - memcpy(buf, vaddr + offset, csize); + memcpy(kbuf, vaddr + offset, csize); set_iounmap_nonlazy(); iounmap((void __iomem *)vaddr); @@ -43,39 +43,35 @@ static ssize_t __copy_oldmem_page(unsigned long pfn, char *buf, size_t csize, } /** - * copy_oldmem_page - copy one page of memory + * copy_oldmem_page_buf - copy one page of memory * @pfn: page frame number to be copied - * @buf: target memory address for the copy; this can be in kernel address - * space or user address space (see @userbuf) + * @ubuf: target user memory pointer for the copy; use copy_to_user() if this + * pointer is not NULL + * @kbuf: target kernel memory pointer for the copy; use memcpy() if this + * pointer is not NULL * @csize: number of bytes to copy * @offset: offset in bytes into the page (based on pfn) to begin the copy - * @userbuf: if set, @buf is in user address space, use copy_to_user(), - * otherwise @buf is in kernel address space, use memcpy(). * - * Copy a page from the old kernel's memory. For this page, there is no pte - * mapped in the current kernel. We stitch up a pte, similar to kmap_atomic. + * Copy a page from the old kernel's memory into the buffer pointed either by + * @ubuf or @kbuf. For this page, there is no pte mapped in the current kernel. + * We stitch up a pte, similar to kmap_atomic. */ -ssize_t copy_oldmem_page(unsigned long pfn, char *buf, size_t csize, - unsigned long offset, int userbuf) +ssize_t copy_oldmem_page_buf(unsigned long pfn, char __user *ubuf, char *kbuf, + size_t csize, unsigned long offset) { - return __copy_oldmem_page(pfn, buf, csize, offset, userbuf, false); + return __copy_oldmem_page(pfn, ubuf, kbuf, csize, offset, false); } /** - * copy_oldmem_page_encrypted - same as copy_oldmem_page() above but ioremap the - * memory with the encryption mask set to accommodate kdump on SME-enabled + * copy_oldmem_page_encrypted - same as copy_oldmem_page_buf() above but ioremap + * the memory with the encryption mask set to accommodate kdump on SME-enabled * machines. */ ssize_t copy_oldmem_page_encrypted(unsigned long pfn, char __user *ubuf, char *kbuf, size_t csize, unsigned long offset) { - if (ubuf) - return __copy_oldmem_page(pfn, (__force char *)ubuf, csize, - offset, 1, true); - else - return __copy_oldmem_page(pfn, kbuf, csize, - offset, 0, true); + return __copy_oldmem_page(pfn, ubuf, kbuf, csize, offset, true); } ssize_t elfcorehdr_read(char *buf, size_t count, u64 *ppos) From patchwork Fri Dec 3 10:42:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Daniel Kachhap X-Patchwork-Id: 12654769 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 181DDC433EF for ; Fri, 3 Dec 2021 10:43:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380086AbhLCKqp (ORCPT ); Fri, 3 Dec 2021 05:46:45 -0500 Received: from foss.arm.com ([217.140.110.172]:46994 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379967AbhLCKqf (ORCPT ); Fri, 3 Dec 2021 05:46:35 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id AB53E1570; Fri, 3 Dec 2021 02:43:11 -0800 (PST) Received: from a077416.arm.com (unknown [10.163.33.180]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 5DCFB3F5A1; Fri, 3 Dec 2021 02:43:07 -0800 (PST) From: Amit Daniel Kachhap To: linux-kernel@vger.kernel.org Cc: Christoph Hellwig , Vincenzo Frascino , Kevin Brodsky , linux-fsdevel , kexec , Amit Daniel Kachhap , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86 Subject: [RFC PATCH 05/14] x86/crash_dump_32: Use the new interface copy_oldmem_page_buf Date: Fri, 3 Dec 2021 16:12:22 +0530 Message-Id: <20211203104231.17597-6-amit.kachhap@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211203104231.17597-1-amit.kachhap@arm.com> References: <20211203104231.17597-1-amit.kachhap@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The current interface copy_oldmem_page() passes user pointer without __user annotation and hence does unnecessary user/kernel pointer conversions during its implementation. Implement the interface copy_oldmem_page_buf() to avoid this issue. Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Borislav Petkov Cc: Dave Hansen Cc: x86 Signed-off-by: Amit Daniel Kachhap --- arch/x86/kernel/crash_dump_32.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/arch/x86/kernel/crash_dump_32.c b/arch/x86/kernel/crash_dump_32.c index 5fcac46aaf6b..9932cd62ded1 100644 --- a/arch/x86/kernel/crash_dump_32.c +++ b/arch/x86/kernel/crash_dump_32.c @@ -30,20 +30,20 @@ static inline bool is_crashed_pfn_valid(unsigned long pfn) } /** - * copy_oldmem_page - copy one page from "oldmem" + * copy_oldmem_page_buf - copy one page from "oldmem" * @pfn: page frame number to be copied - * @buf: target memory address for the copy; this can be in kernel address - * space or user address space (see @userbuf) + * @ubuf: target user memory pointer for the copy; use copy_to_user() if this + * pointer is not NULL + * @kbuf: target kernel memory pointer for the copy; use memcpy() if this + * pointer is not NULL * @csize: number of bytes to copy * @offset: offset in bytes into the page (based on pfn) to begin the copy - * @userbuf: if set, @buf is in user address space, use copy_to_user(), - * otherwise @buf is in kernel address space, use memcpy(). * - * Copy a page from "oldmem". For this page, there might be no pte mapped - * in the current kernel. + * Copy a page from "oldmem" into the buffer pointed by either @ubuf or @kbuf. + * For this page, there might be no pte mapped in the current kernel. */ -ssize_t copy_oldmem_page(unsigned long pfn, char *buf, size_t csize, - unsigned long offset, int userbuf) +ssize_t copy_oldmem_page_buf(unsigned long pfn, char __user *ubuf, char *kbuf, + size_t csize, unsigned long offset) { void *vaddr; @@ -55,10 +55,10 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf, size_t csize, vaddr = kmap_local_pfn(pfn); - if (!userbuf) { - memcpy(buf, vaddr + offset, csize); + if (!ubuf) { + memcpy(kbuf, vaddr + offset, csize); } else { - if (copy_to_user(buf, vaddr + offset, csize)) + if (copy_to_user(ubuf, vaddr + offset, csize)) csize = -EFAULT; } From patchwork Fri Dec 3 10:42:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Daniel Kachhap X-Patchwork-Id: 12654777 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77F85C433EF for ; Fri, 3 Dec 2021 10:43:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380034AbhLCKq6 (ORCPT ); Fri, 3 Dec 2021 05:46:58 -0500 Received: from foss.arm.com ([217.140.110.172]:47012 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380053AbhLCKqj (ORCPT ); Fri, 3 Dec 2021 05:46:39 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id F19C61576; Fri, 3 Dec 2021 02:43:15 -0800 (PST) Received: from a077416.arm.com (unknown [10.163.33.180]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 494573F5A1; Fri, 3 Dec 2021 02:43:11 -0800 (PST) From: Amit Daniel Kachhap To: linux-kernel@vger.kernel.org Cc: Christoph Hellwig , Vincenzo Frascino , Kevin Brodsky , linux-fsdevel , kexec , Amit Daniel Kachhap , Catalin Marinas , Will Deacon , linux-arm-kernel Subject: [RFC PATCH 06/14] arm64/crash_dump: Use the new interface copy_oldmem_page_buf Date: Fri, 3 Dec 2021 16:12:23 +0530 Message-Id: <20211203104231.17597-7-amit.kachhap@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211203104231.17597-1-amit.kachhap@arm.com> References: <20211203104231.17597-1-amit.kachhap@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The current interface copy_oldmem_page() passes user pointer without __user annotation and hence does unnecessary user/kernel pointer conversions during its implementation. Implement the interface copy_oldmem_page_buf() to avoid this issue. Cc: Catalin Marinas Cc: Will Deacon Cc: linux-arm-kernel Signed-off-by: Amit Daniel Kachhap --- arch/arm64/kernel/crash_dump.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/arch/arm64/kernel/crash_dump.c b/arch/arm64/kernel/crash_dump.c index 58303a9ec32c..ec9d5c80726c 100644 --- a/arch/arm64/kernel/crash_dump.c +++ b/arch/arm64/kernel/crash_dump.c @@ -14,20 +14,19 @@ #include /** - * copy_oldmem_page() - copy one page from old kernel memory + * copy_oldmem_page_buf() - copy one page from old kernel memory * @pfn: page frame number to be copied - * @buf: buffer where the copied page is placed + * @ubuf: user buffer where the copied page is placed + * @kbuf: kernel buffer where the copied page is placed * @csize: number of bytes to copy * @offset: offset in bytes into the page - * @userbuf: if set, @buf is in a user address space * * This function copies one page from old kernel memory into buffer pointed by - * @buf. If @buf is in userspace, set @userbuf to %1. Returns number of bytes - * copied or negative error in case of failure. + * either @ubuf or @kbuf. Returns number of bytes copied or negative error in + * case of failure. */ -ssize_t copy_oldmem_page(unsigned long pfn, char *buf, - size_t csize, unsigned long offset, - int userbuf) +ssize_t copy_oldmem_page_buf(unsigned long pfn, char __user *ubuf, char *kbuf, + size_t csize, unsigned long offset) { void *vaddr; @@ -38,13 +37,13 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf, if (!vaddr) return -ENOMEM; - if (userbuf) { - if (copy_to_user((char __user *)buf, vaddr + offset, csize)) { + if (ubuf) { + if (copy_to_user(ubuf, vaddr + offset, csize)) { memunmap(vaddr); return -EFAULT; } } else { - memcpy(buf, vaddr + offset, csize); + memcpy(kbuf, vaddr + offset, csize); } memunmap(vaddr); From patchwork Fri Dec 3 10:42:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Daniel Kachhap X-Patchwork-Id: 12654771 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46310C433EF for ; Fri, 3 Dec 2021 10:43:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380107AbhLCKqt (ORCPT ); Fri, 3 Dec 2021 05:46:49 -0500 Received: from foss.arm.com ([217.140.110.172]:47022 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380066AbhLCKqn (ORCPT ); Fri, 3 Dec 2021 05:46:43 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DA0901595; Fri, 3 Dec 2021 02:43:19 -0800 (PST) Received: from a077416.arm.com (unknown [10.163.33.180]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 849863F5A1; Fri, 3 Dec 2021 02:43:16 -0800 (PST) From: Amit Daniel Kachhap To: linux-kernel@vger.kernel.org Cc: Christoph Hellwig , Vincenzo Frascino , Kevin Brodsky , linux-fsdevel , kexec , Amit Daniel Kachhap , Russell King , linux-arm-kernel Subject: [RFC PATCH 07/14] arm/crash_dump: Use the new interface copy_oldmem_page_buf Date: Fri, 3 Dec 2021 16:12:24 +0530 Message-Id: <20211203104231.17597-8-amit.kachhap@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211203104231.17597-1-amit.kachhap@arm.com> References: <20211203104231.17597-1-amit.kachhap@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The current interface copy_oldmem_page() passes user pointer without __user annotation and hence does unnecessary user/kernel pointer conversions during its implementation. Implement the interface copy_oldmem_page_buf() to avoid this issue. Cc: Russell King Cc: linux-arm-kernel Signed-off-by: Amit Daniel Kachhap --- arch/arm/kernel/crash_dump.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/arch/arm/kernel/crash_dump.c b/arch/arm/kernel/crash_dump.c index 53cb92435392..bb0395ab9f98 100644 --- a/arch/arm/kernel/crash_dump.c +++ b/arch/arm/kernel/crash_dump.c @@ -16,20 +16,19 @@ #include /** - * copy_oldmem_page() - copy one page from old kernel memory + * copy_oldmem_page_buf() - copy one page from old kernel memory * @pfn: page frame number to be copied - * @buf: buffer where the copied page is placed + * @ubuf: user buffer where the copied page is placed + * @kbuf: kernel buffer where the copied page is placed * @csize: number of bytes to copy * @offset: offset in bytes into the page - * @userbuf: if set, @buf is int he user address space * * This function copies one page from old kernel memory into buffer pointed by - * @buf. If @buf is in userspace, set @userbuf to %1. Returns number of bytes - * copied or negative error in case of failure. + * either @ubuf or @kbuf. Returns number of bytes copied or negative error in + * case of failure. */ -ssize_t copy_oldmem_page(unsigned long pfn, char *buf, - size_t csize, unsigned long offset, - int userbuf) +ssize_t copy_oldmem_page_buf(unsigned long pfn, char __user *ubuf, char *kbuf, + size_t csize, unsigned long offset) { void *vaddr; @@ -40,13 +39,13 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf, if (!vaddr) return -ENOMEM; - if (userbuf) { - if (copy_to_user(buf, vaddr + offset, csize)) { + if (ubuf) { + if (copy_to_user(ubuf, vaddr + offset, csize)) { iounmap(vaddr); return -EFAULT; } } else { - memcpy(buf, vaddr + offset, csize); + memcpy(kbuf, vaddr + offset, csize); } iounmap(vaddr); From patchwork Fri Dec 3 10:42:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Daniel Kachhap X-Patchwork-Id: 12654773 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82E6AC433FE for ; Fri, 3 Dec 2021 10:43:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380124AbhLCKqv (ORCPT ); Fri, 3 Dec 2021 05:46:51 -0500 Received: from foss.arm.com ([217.140.110.172]:47032 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380100AbhLCKqr (ORCPT ); Fri, 3 Dec 2021 05:46:47 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id B6CDE1597; Fri, 3 Dec 2021 02:43:23 -0800 (PST) Received: from a077416.arm.com (unknown [10.163.33.180]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 6E1283F5A1; Fri, 3 Dec 2021 02:43:20 -0800 (PST) From: Amit Daniel Kachhap To: linux-kernel@vger.kernel.org Cc: Christoph Hellwig , Vincenzo Frascino , Kevin Brodsky , linux-fsdevel , kexec , Amit Daniel Kachhap , Thomas Bogendoerfer , linux-mips Subject: [RFC PATCH 08/14] mips/crash_dump: Use the new interface copy_oldmem_page_buf Date: Fri, 3 Dec 2021 16:12:25 +0530 Message-Id: <20211203104231.17597-9-amit.kachhap@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211203104231.17597-1-amit.kachhap@arm.com> References: <20211203104231.17597-1-amit.kachhap@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The current interface copy_oldmem_page() passes user pointer without __user annotation and hence does unnecessary user/kernel pointer conversions during its implementation. Use the interface copy_oldmem_page_buf() to avoid this issue. Cc: Thomas Bogendoerfer Cc: linux-mips Signed-off-by: Amit Daniel Kachhap --- arch/mips/kernel/crash_dump.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/arch/mips/kernel/crash_dump.c b/arch/mips/kernel/crash_dump.c index 2e50f55185a6..f2406b868a27 100644 --- a/arch/mips/kernel/crash_dump.c +++ b/arch/mips/kernel/crash_dump.c @@ -3,20 +3,20 @@ #include /** - * copy_oldmem_page - copy one page from "oldmem" + * copy_oldmem_page_buf - copy one page from "oldmem" * @pfn: page frame number to be copied - * @buf: target memory address for the copy; this can be in kernel address - * space or user address space (see @userbuf) + * @ubuf: target user memory pointer for the copy; use copy_to_user() if this + * pointer is not NULL + * @kbuf: target kernel memory pointer for the copy; use memcpy() if this + * pointer is not NULL * @csize: number of bytes to copy * @offset: offset in bytes into the page (based on pfn) to begin the copy - * @userbuf: if set, @buf is in user address space, use copy_to_user(), - * otherwise @buf is in kernel address space, use memcpy(). * - * Copy a page from "oldmem". For this page, there is no pte mapped - * in the current kernel. + * Copy a page from "oldmem" into buffer pointed by either @ubuf or @kbuf. For + * this page, there is no pte mapped in the current kernel. */ -ssize_t copy_oldmem_page(unsigned long pfn, char *buf, - size_t csize, unsigned long offset, int userbuf) +ssize_t copy_oldmem_page_buf(unsigned long pfn, char __user *ubuf, char *kbuf, + size_t csize, unsigned long offset) { void *vaddr; @@ -25,10 +25,10 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf, vaddr = kmap_local_pfn(pfn); - if (!userbuf) { - memcpy(buf, vaddr + offset, csize); + if (kbuf) { + memcpy(kbuf, vaddr + offset, csize); } else { - if (copy_to_user(buf, vaddr + offset, csize)) + if (copy_to_user(ubuf, vaddr + offset, csize)) csize = -EFAULT; } From patchwork Fri Dec 3 10:42:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Daniel Kachhap X-Patchwork-Id: 12654775 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41AE5C433FE for ; Fri, 3 Dec 2021 10:43:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380137AbhLCKqx (ORCPT ); Fri, 3 Dec 2021 05:46:53 -0500 Received: from foss.arm.com ([217.140.110.172]:47044 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380122AbhLCKqw (ORCPT ); Fri, 3 Dec 2021 05:46:52 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id F0B571596; Fri, 3 Dec 2021 02:43:27 -0800 (PST) Received: from a077416.arm.com (unknown [10.163.33.180]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 5D81C3F5A1; Fri, 3 Dec 2021 02:43:24 -0800 (PST) From: Amit Daniel Kachhap To: linux-kernel@vger.kernel.org Cc: Christoph Hellwig , Vincenzo Frascino , Kevin Brodsky , linux-fsdevel , kexec , Amit Daniel Kachhap , Yoshinori Sato , Rich Felker , linux-sh Subject: [RFC PATCH 09/14] sh/crash_dump: Use the new interface copy_oldmem_page_buf Date: Fri, 3 Dec 2021 16:12:26 +0530 Message-Id: <20211203104231.17597-10-amit.kachhap@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211203104231.17597-1-amit.kachhap@arm.com> References: <20211203104231.17597-1-amit.kachhap@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The current interface copy_oldmem_page() passes user pointer without __user annotation and hence does unnecessary user/kernel pointer conversions during its implementation. Use the interface copy_oldmem_page_buf() to avoid this issue. Cc: Yoshinori Sato Cc: Rich Felker CC: linux-sh Signed-off-by: Amit Daniel Kachhap --- arch/sh/kernel/crash_dump.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/arch/sh/kernel/crash_dump.c b/arch/sh/kernel/crash_dump.c index 5b41b59698c1..a80dedf1ace5 100644 --- a/arch/sh/kernel/crash_dump.c +++ b/arch/sh/kernel/crash_dump.c @@ -11,20 +11,21 @@ #include /** - * copy_oldmem_page - copy one page from "oldmem" + * copy_oldmem_page_buf - copy one page from "oldmem" * @pfn: page frame number to be copied - * @buf: target memory address for the copy; this can be in kernel address - * space or user address space (see @userbuf) + * @ubuf: target user memory pointer for the copy; use copy_to_user() if this + * pointer is not NULL + * @kbuf: target kernel memory pointer for the copy; use memcpy() if this + * pointer is not NULL * @csize: number of bytes to copy * @offset: offset in bytes into the page (based on pfn) to begin the copy - * @userbuf: if set, @buf is in user address space, use copy_to_user(), - * otherwise @buf is in kernel address space, use memcpy(). * - * Copy a page from "oldmem". For this page, there is no pte mapped - * in the current kernel. We stitch up a pte, similar to kmap_atomic. + * Copy a page from "oldmem" into the buffer pointed by either @ubuf or @kbuf. + * For this page, there is no pte mapped in the current kernel. We stitch up a + * pte, similar to kmap_atomic. */ -ssize_t copy_oldmem_page(unsigned long pfn, char *buf, - size_t csize, unsigned long offset, int userbuf) +ssize_t copy_oldmem_page_buf(unsigned long pfn, char __user *ubuf, char *kbuf, + size_t csize, unsigned long offset) { void __iomem *vaddr; @@ -33,13 +34,13 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf, vaddr = ioremap(pfn << PAGE_SHIFT, PAGE_SIZE); - if (userbuf) { - if (copy_to_user((void __user *)buf, (vaddr + offset), csize)) { + if (ubuf) { + if (copy_to_user(ubuf, (vaddr + offset), csize)) { iounmap(vaddr); return -EFAULT; } } else - memcpy(buf, (vaddr + offset), csize); + memcpy(kbuf, (vaddr + offset), csize); iounmap(vaddr); return csize; From patchwork Fri Dec 3 10:42:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Daniel Kachhap X-Patchwork-Id: 12654779 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 328C9C433F5 for ; Fri, 3 Dec 2021 10:43:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380112AbhLCKrF (ORCPT ); Fri, 3 Dec 2021 05:47:05 -0500 Received: from foss.arm.com ([217.140.110.172]:47054 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380105AbhLCKq4 (ORCPT ); Fri, 3 Dec 2021 05:46:56 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 77EF415A1; Fri, 3 Dec 2021 02:43:32 -0800 (PST) Received: from a077416.arm.com (unknown [10.163.33.180]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 89AF53F5A1; Fri, 3 Dec 2021 02:43:28 -0800 (PST) From: Amit Daniel Kachhap To: linux-kernel@vger.kernel.org Cc: Christoph Hellwig , Vincenzo Frascino , Kevin Brodsky , linux-fsdevel , kexec , Amit Daniel Kachhap , Paul Walmsley , Palmer Dabbelt , Albert Ou , linux-riscv Subject: [RFC PATCH 10/14] riscv/crash_dump: Use the new interface copy_oldmem_page_buf Date: Fri, 3 Dec 2021 16:12:27 +0530 Message-Id: <20211203104231.17597-11-amit.kachhap@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211203104231.17597-1-amit.kachhap@arm.com> References: <20211203104231.17597-1-amit.kachhap@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The current interface copy_oldmem_page() passes user pointer without __user annotation and hence does unnecessary user/kernel pointer conversions during its implementation. Use the interface copy_oldmem_page_buf() to avoid this issue. Cc: Paul Walmsley Cc: Palmer Dabbelt Cc: Albert Ou Cc: linux-riscv Signed-off-by: Amit Daniel Kachhap --- arch/riscv/kernel/crash_dump.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/arch/riscv/kernel/crash_dump.c b/arch/riscv/kernel/crash_dump.c index 86cc0ada5752..3a8fadcd1278 100644 --- a/arch/riscv/kernel/crash_dump.c +++ b/arch/riscv/kernel/crash_dump.c @@ -9,20 +9,21 @@ #include /** - * copy_oldmem_page() - copy one page from old kernel memory + * copy_oldmem_page_buf() - copy one page from old kernel memory * @pfn: page frame number to be copied - * @buf: buffer where the copied page is placed + * @ubuf: user buffer where the copied page is placed; use copy_to_user() if + * this pointer is not NULL + * @kbuf: kernel buffer where the copied page is placed; use memcpy() if this + * pointer is not NULL * @csize: number of bytes to copy * @offset: offset in bytes into the page - * @userbuf: if set, @buf is in a user address space * - * This function copies one page from old kernel memory into buffer pointed by - * @buf. If @buf is in userspace, set @userbuf to %1. Returns number of bytes - * copied or negative error in case of failure. + * This function copies one page from old kernel memory into the buffer pointed + * by either @ubuf or @kbuf. Returns number of bytes copied or negative error in + * case of failure. */ -ssize_t copy_oldmem_page(unsigned long pfn, char *buf, - size_t csize, unsigned long offset, - int userbuf) +ssize_t copy_oldmem_page_buf(unsigned long pfn, char __user *ubuf, char *kbuf, + size_t csize, unsigned long offset) { void *vaddr; @@ -33,13 +34,13 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf, if (!vaddr) return -ENOMEM; - if (userbuf) { - if (copy_to_user((char __user *)buf, vaddr + offset, csize)) { + if (ubuf) { + if (copy_to_user(ubuf, vaddr + offset, csize)) { memunmap(vaddr); return -EFAULT; } } else - memcpy(buf, vaddr + offset, csize); + memcpy(kbuf, vaddr + offset, csize); memunmap(vaddr); return csize; From patchwork Fri Dec 3 10:42:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Daniel Kachhap X-Patchwork-Id: 12654799 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F08E0C433F5 for ; Fri, 3 Dec 2021 10:43:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352053AbhLCKrL (ORCPT ); Fri, 3 Dec 2021 05:47:11 -0500 Received: from foss.arm.com ([217.140.110.172]:47076 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380141AbhLCKrA (ORCPT ); Fri, 3 Dec 2021 05:47:00 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id F311A15AD; Fri, 3 Dec 2021 02:43:36 -0800 (PST) Received: from a077416.arm.com (unknown [10.163.33.180]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 1539C3F5A1; Fri, 3 Dec 2021 02:43:32 -0800 (PST) From: Amit Daniel Kachhap To: linux-kernel@vger.kernel.org Cc: Christoph Hellwig , Vincenzo Frascino , Kevin Brodsky , linux-fsdevel , kexec , Amit Daniel Kachhap , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , linuxppc Subject: [RFC PATCH 11/14] powerpc/crash_dump: Use the new interface copy_oldmem_page_buf Date: Fri, 3 Dec 2021 16:12:28 +0530 Message-Id: <20211203104231.17597-12-amit.kachhap@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211203104231.17597-1-amit.kachhap@arm.com> References: <20211203104231.17597-1-amit.kachhap@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The current interface copy_oldmem_page() passes user pointer without __user annotation and hence does unnecessary user/kernel pointer conversions during its implementation. Use the interface copy_oldmem_page_buf() to avoid this issue. Cc: Michael Ellerman CC: Benjamin Herrenschmidt Cc: Paul Mackerras Cc: linuxppc Signed-off-by: Amit Daniel Kachhap --- arch/powerpc/kernel/crash_dump.c | 33 ++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/arch/powerpc/kernel/crash_dump.c b/arch/powerpc/kernel/crash_dump.c index 5693e1c67c2b..a1c8a3a11694 100644 --- a/arch/powerpc/kernel/crash_dump.c +++ b/arch/powerpc/kernel/crash_dump.c @@ -68,33 +68,34 @@ void __init setup_kdump_trampoline(void) } #endif /* CONFIG_NONSTATIC_KERNEL */ -static size_t copy_oldmem_vaddr(void *vaddr, char *buf, size_t csize, - unsigned long offset, int userbuf) +static size_t copy_oldmem_vaddr(void *vaddr, char __user *ubuf, char *kbuf, + size_t csize, unsigned long offset) { - if (userbuf) { - if (copy_to_user((char __user *)buf, (vaddr + offset), csize)) + if (ubuf) { + if (copy_to_user(ubuf, (vaddr + offset), csize)) return -EFAULT; } else - memcpy(buf, (vaddr + offset), csize); + memcpy(kbuf, (vaddr + offset), csize); return csize; } /** - * copy_oldmem_page - copy one page from "oldmem" + * copy_oldmem_page_buf - copy one page from "oldmem" * @pfn: page frame number to be copied - * @buf: target memory address for the copy; this can be in kernel address - * space or user address space (see @userbuf) + * @ubuf: target user memory address for the copy; use copy_to_user() if this + * address is present + * @kbuf: target kernel memory address for the copy; use memcpy() if this + * address is present * @csize: number of bytes to copy * @offset: offset in bytes into the page (based on pfn) to begin the copy - * @userbuf: if set, @buf is in user address space, use copy_to_user(), - * otherwise @buf is in kernel address space, use memcpy(). * - * Copy a page from "oldmem". For this page, there is no pte mapped - * in the current kernel. We stitch up a pte, similar to kmap_atomic. + * Copy a page from "oldmem" into buffer pointed by either @ubuf or @kbuf. For + * this page, there is no pte mapped in the current kernel. We stitch up a pte, + * similar to kmap_atomic. */ -ssize_t copy_oldmem_page(unsigned long pfn, char *buf, - size_t csize, unsigned long offset, int userbuf) +ssize_t copy_oldmem_page_buf(unsigned long pfn, char __user *ubuf, char *kbuf, + size_t csize, unsigned long offset) { void *vaddr; phys_addr_t paddr; @@ -107,10 +108,10 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf, if (memblock_is_region_memory(paddr, csize)) { vaddr = __va(paddr); - csize = copy_oldmem_vaddr(vaddr, buf, csize, offset, userbuf); + csize = copy_oldmem_vaddr(vaddr, ubuf, kbuf, csize, offset); } else { vaddr = ioremap_cache(paddr, PAGE_SIZE); - csize = copy_oldmem_vaddr(vaddr, buf, csize, offset, userbuf); + csize = copy_oldmem_vaddr(vaddr, ubuf, kbuf, csize, offset); iounmap(vaddr); } From patchwork Fri Dec 3 10:42:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Daniel Kachhap X-Patchwork-Id: 12654801 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C393C433EF for ; Fri, 3 Dec 2021 10:43:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380140AbhLCKrO (ORCPT ); Fri, 3 Dec 2021 05:47:14 -0500 Received: from foss.arm.com ([217.140.110.172]:47098 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380165AbhLCKrE (ORCPT ); Fri, 3 Dec 2021 05:47:04 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 8492815BE; Fri, 3 Dec 2021 02:43:40 -0800 (PST) Received: from a077416.arm.com (unknown [10.163.33.180]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 90A9A3F5A1; Fri, 3 Dec 2021 02:43:37 -0800 (PST) From: Amit Daniel Kachhap To: linux-kernel@vger.kernel.org Cc: Christoph Hellwig , Vincenzo Frascino , Kevin Brodsky , linux-fsdevel , kexec , Amit Daniel Kachhap , linux-ia64 Subject: [RFC PATCH 12/14] ia64/crash_dump: Use the new interface copy_oldmem_page_buf Date: Fri, 3 Dec 2021 16:12:29 +0530 Message-Id: <20211203104231.17597-13-amit.kachhap@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211203104231.17597-1-amit.kachhap@arm.com> References: <20211203104231.17597-1-amit.kachhap@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The current interface copy_oldmem_page() passes user pointer without __user annotation and hence does unnecessary user/kernel pointer conversions during its implementation. Use the interface copy_oldmem_page_buf() to avoid this issue. Cc: linux-ia64 Signed-off-by: Amit Daniel Kachhap --- arch/ia64/kernel/crash_dump.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/arch/ia64/kernel/crash_dump.c b/arch/ia64/kernel/crash_dump.c index 0ed3c3dee4cd..1aea8dbe06de 100644 --- a/arch/ia64/kernel/crash_dump.c +++ b/arch/ia64/kernel/crash_dump.c @@ -15,37 +15,38 @@ #include /** - * copy_oldmem_page - copy one page from "oldmem" + * copy_oldmem_page_buf - copy one page from "oldmem" * @pfn: page frame number to be copied - * @buf: target memory address for the copy; this can be in kernel address - * space or user address space (see @userbuf) + * @ubuf: target user memory pointer for the copy; use copy_to_user() if this + * pointer is not NULL + * @kbuf: target kernel memory pointer for the copy; use memcpy() if this + * pointer is not NULL * @csize: number of bytes to copy * @offset: offset in bytes into the page (based on pfn) to begin the copy - * @userbuf: if set, @buf is in user address space, use copy_to_user(), - * otherwise @buf is in kernel address space, use memcpy(). * - * Copy a page from "oldmem". For this page, there is no pte mapped - * in the current kernel. We stitch up a pte, similar to kmap_atomic. + * Copy a page from "oldmem" into the buffer pointed by either @ubuf or @kbuf. + * For this page, there is no pte mapped in the current kernel. We stitch up a + * pte, similar to kmap_atomic. * * 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) +copy_oldmem_page_buf(unsigned long pfn, char __user *ubuf, char *kbuf, + size_t csize, unsigned long offset) { void *vaddr; if (!csize) return 0; vaddr = __va(pfn< X-Patchwork-Id: 12654803 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EAE44C433FE for ; Fri, 3 Dec 2021 10:43:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380173AbhLCKrS (ORCPT ); Fri, 3 Dec 2021 05:47:18 -0500 Received: from foss.arm.com ([217.140.110.172]:47116 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380187AbhLCKrJ (ORCPT ); Fri, 3 Dec 2021 05:47:09 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 365D315BF; Fri, 3 Dec 2021 02:43:45 -0800 (PST) Received: from a077416.arm.com (unknown [10.163.33.180]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 187413F5A1; Fri, 3 Dec 2021 02:43:40 -0800 (PST) From: Amit Daniel Kachhap To: linux-kernel@vger.kernel.org Cc: Christoph Hellwig , Vincenzo Frascino , Kevin Brodsky , linux-fsdevel , kexec , Amit Daniel Kachhap , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Alexander Gordeev , linux-s390 Subject: [RFC PATCH 13/14] s390/crash_dump: Use the new interface copy_oldmem_page_buf Date: Fri, 3 Dec 2021 16:12:30 +0530 Message-Id: <20211203104231.17597-14-amit.kachhap@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211203104231.17597-1-amit.kachhap@arm.com> References: <20211203104231.17597-1-amit.kachhap@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org The current interface copy_oldmem_page() passes user pointer without __user annotation and hence does unnecessary user/kernel pointer conversions during its implementation. Use the interface copy_oldmem_page_buf() to avoid this issue. Cc: Heiko Carstens Cc: Vasily Gorbik Cc: Christian Borntraeger CC: Alexander Gordeev Cc: linux-s390 Signed-off-by: Amit Daniel Kachhap --- arch/s390/kernel/crash_dump.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/arch/s390/kernel/crash_dump.c b/arch/s390/kernel/crash_dump.c index 785d54c9350c..b1f8a908e8ca 100644 --- a/arch/s390/kernel/crash_dump.c +++ b/arch/s390/kernel/crash_dump.c @@ -214,8 +214,8 @@ static int copy_oldmem_user(void __user *dst, void *src, size_t count) /* * Copy one page from "oldmem" */ -ssize_t copy_oldmem_page(unsigned long pfn, char *buf, size_t csize, - unsigned long offset, int userbuf) +ssize_t copy_oldmem_page_buf(unsigned long pfn, char __user *ubuf, char *kbuf, + size_t csize, unsigned long offset) { void *src; int rc; @@ -223,10 +223,10 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf, size_t csize, if (!csize) return 0; src = (void *) (pfn << PAGE_SHIFT) + offset; - if (userbuf) - rc = copy_oldmem_user((void __force __user *) buf, src, csize); + if (ubuf) + rc = copy_oldmem_user((void __user *) ubuf, src, csize); else - rc = copy_oldmem_kernel((void *) buf, src, csize); + rc = copy_oldmem_kernel((void *) kbuf, src, csize); return rc; } @@ -261,7 +261,7 @@ static int remap_oldmem_pfn_range_kdump(struct vm_area_struct *vma, * Remap "oldmem" for zfcp/nvme dump * * We only map available memory above HSA size. Memory below HSA size - * is read on demand using the copy_oldmem_page() function. + * is read on demand using the copy_oldmem_page_buf() function. */ static int remap_oldmem_pfn_range_zfcpdump(struct vm_area_struct *vma, unsigned long from, From patchwork Fri Dec 3 10:42:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amit Daniel Kachhap X-Patchwork-Id: 12654805 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78858C433F5 for ; Fri, 3 Dec 2021 10:44:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1380241AbhLCKr1 (ORCPT ); Fri, 3 Dec 2021 05:47:27 -0500 Received: from foss.arm.com ([217.140.110.172]:47132 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1380205AbhLCKrN (ORCPT ); Fri, 3 Dec 2021 05:47:13 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 76C7D1576; Fri, 3 Dec 2021 02:43:49 -0800 (PST) Received: from a077416.arm.com (unknown [10.163.33.180]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id BF8903F5A1; Fri, 3 Dec 2021 02:43:45 -0800 (PST) From: Amit Daniel Kachhap To: linux-kernel@vger.kernel.org Cc: Christoph Hellwig , Vincenzo Frascino , Kevin Brodsky , linux-fsdevel , kexec , Amit Daniel Kachhap , Dave Young , Baoquan He , Vivek Goyal Subject: [RFC PATCH 14/14] fs/proc/vmcore: Remove the unused old interface copy_oldmem_page Date: Fri, 3 Dec 2021 16:12:31 +0530 Message-Id: <20211203104231.17597-15-amit.kachhap@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211203104231.17597-1-amit.kachhap@arm.com> References: <20211203104231.17597-1-amit.kachhap@arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org As all archs have upgraded to use the new interface copy_oldmem_page_buf() so remove the unused copy_oldmem_page. Also remove the weak definitions. Cc: Dave Young Cc: Baoquan He Cc: Vivek Goyal Cc: kexec Cc: linux-fsdevel Signed-off-by: Amit Daniel Kachhap --- fs/proc/vmcore.c | 14 -------------- include/linux/crash_dump.h | 2 -- 2 files changed, 16 deletions(-) diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c index d01b85c043dd..1edababe4bde 100644 --- a/fs/proc/vmcore.c +++ b/fs/proc/vmcore.c @@ -244,20 +244,6 @@ copy_oldmem_page_encrypted(unsigned long pfn, char __user *ubuf, char *kbuf, return copy_oldmem_page_buf(pfn, ubuf, kbuf, csize, offset); } -ssize_t __weak -copy_oldmem_page_buf(unsigned long pfn, char __user *ubuf, char *kbuf, - size_t csize, unsigned long offset) -{ - return -EOPNOTSUPP; -} - -ssize_t __weak -copy_oldmem_page(unsigned long pfn, char *ubuf, size_t csize, - unsigned long offset, int userbuf) -{ - return -EOPNOTSUPP; -} - /* * Copy to either kernel or user space buffer */ diff --git a/include/linux/crash_dump.h b/include/linux/crash_dump.h index 725c4e053ecf..e897bdc0b7bf 100644 --- a/include/linux/crash_dump.h +++ b/include/linux/crash_dump.h @@ -24,8 +24,6 @@ extern int remap_oldmem_pfn_range(struct vm_area_struct *vma, unsigned long from, unsigned long pfn, unsigned long size, pgprot_t prot); -extern ssize_t copy_oldmem_page(unsigned long, char *, size_t, - unsigned long, int); extern ssize_t copy_oldmem_page_buf(unsigned long pfn, char __user *ubuf, char *kbuf, size_t csize, unsigned long offset);