Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S967485Ab3DRJf0 (ORCPT ); Thu, 18 Apr 2013 05:35:26 -0400 Received: from fgwmail6.fujitsu.co.jp ([192.51.44.36]:43951 "EHLO fgwmail6.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967442Ab3DRJfY (ORCPT ); Thu, 18 Apr 2013 05:35:24 -0400 From: HATAYAMA Daisuke Subject: [PATCH v4 8/8] vmcore: support mmap() on /proc/vmcore To: vgoyal@redhat.com, ebiederm@xmission.com, akpm@linux-foundation.org Cc: cpw@sgi.com, kumagai-atsushi@mxc.nes.nec.co.jp, lisa.mitchell@hp.com, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, zhangyanfei@cn.fujitsu.com, jingbai.ma@hp.com Date: Sat, 13 Apr 2013 09:21:51 +0900 Message-ID: <20130413002151.18245.23358.stgit@localhost6.localdomain6> In-Reply-To: <20130413002000.18245.21513.stgit@localhost6.localdomain6> References: <20130413002000.18245.21513.stgit@localhost6.localdomain6> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2871 Lines: 108 This patch introduces mmap_vmcore(). If flag MEM_TYPE_CURRENT_KERNEL is set, map buffer on the 2nd kernel. If not set, map some area in old memory. Neither writable nor executable mapping is permitted even with mprotect(). Non-writable mapping is also requirement of remap_pfn_range() when mapping linear pages on non-consequtive physical pages; see is_cow_mapping(). On x86-32 PAE kernels, mmap() supports at most 16TB memory only. This limitation comes from the fact that the third argument of remap_pfn_range(), pfn, is of 32-bit length on x86-32: unsigned long. Signed-off-by: HATAYAMA Daisuke --- fs/proc/vmcore.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 68 insertions(+), 0 deletions(-) diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c index cd0f9d9..aecdc72 100644 --- a/fs/proc/vmcore.c +++ b/fs/proc/vmcore.c @@ -176,9 +176,77 @@ static ssize_t read_vmcore(struct file *file, char __user *buffer, return acc; } +static int mmap_vmcore(struct file *file, struct vm_area_struct *vma) +{ + size_t size = vma->vm_end - vma->vm_start; + u64 start, end, len, tsz; + struct vmcore *m; + + start = (u64)vma->vm_pgoff << PAGE_SHIFT; + end = start + size; + + if (size > vmcore_size || end > vmcore_size) + return -EINVAL; + + if (vma->vm_flags & (VM_WRITE | VM_EXEC)) + return -EPERM; + + vma->vm_flags &= ~(VM_MAYWRITE | VM_MAYEXEC); + + len = 0; + + if (start < elfcorebuf_sz) { + u64 pfn; + + tsz = elfcorebuf_sz - start; + if (size < tsz) + tsz = size; + pfn = __pa(elfcorebuf + start) >> PAGE_SHIFT; + if (remap_pfn_range(vma, vma->vm_start, pfn, tsz, + vma->vm_page_prot)) + return -EAGAIN; + size -= tsz; + start += tsz; + len += tsz; + + if (size == 0) + return 0; + } + + list_for_each_entry(m, &vmcore_list, list) { + if (start < m->offset + m->size) { + u64 paddr = 0; + + tsz = m->offset + m->size - start; + if (size < tsz) + tsz = size; + if (m->flag & MEM_TYPE_CURRENT_KERNEL) { + paddr = __pa(m->buf + start - m->offset); + } else { + paddr = m->paddr + start - m->offset; + } + if (remap_pfn_range(vma, vma->vm_start + len, + paddr >> PAGE_SHIFT, tsz, + vma->vm_page_prot)) { + do_munmap(vma->vm_mm, vma->vm_start, len); + return -EAGAIN; + } + size -= tsz; + start += tsz; + len += tsz; + + if (size == 0) + return 0; + } + } + + return 0; +} + static const struct file_operations proc_vmcore_operations = { .read = read_vmcore, .llseek = default_llseek, + .mmap = mmap_vmcore, }; static struct vmcore* __init get_new_element(void) -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/