Subject: + vmcore-support-mmap-on-proc-vmcore-fix-2.patch added to -mm tree To: d.hatayama@xxxxxxxxxxxxxx,arnd@xxxxxxxx,kosaki.motohiro@xxxxxxxxxxxxxx,kumagai-atsushi@xxxxxxxxxxxxxxxxx,lisa.mitchell@xxxxxx,vgoyal@xxxxxxxxxx,zhangyanfei@xxxxxxxxxxxxxx From: akpm@xxxxxxxxxxxxxxxxxxxx Date: Mon, 10 Jun 2013 16:26:47 -0700 The patch titled Subject: vmcore: disable mmap_vmcore() if CONFIG_MMU is not defined has been added to the -mm tree. Its filename is vmcore-support-mmap-on-proc-vmcore-fix-2.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/SubmitChecklist when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: HATAYAMA Daisuke <d.hatayama@xxxxxxxxxxxxxx> Subject: vmcore: disable mmap_vmcore() if CONFIG_MMU is not defined >From Arnd's report of a link-time build error in vmcore.c, it turned out that mmap_vmcore() work overlooked no-MMU configuraiton. In the current design, it's impossible to implement mmap_vmcore() for no-MMU configuration since MMU is essential in order to map physically non-contiguous objects (ELF header, ELF note segment and memory regions in the 1st kernel pointed to by PT_LOAD entries) into virtually contiguous user-space in ELF layout. Hence, this patch disables mmap_vmcore() if CONFIG_MMU is not defined, returning -ENOSYS. Another change is to fix the build error by using vmalloc_user() instead of calling vzalloc() and find_vm_area() in order, by which we no longer need to call find_vm_area() in vmcore.c that has no counterpart on non-MMU configuration. Also, on no-MMU configuration, because we don't export buffer for ELF note segment to user-space, we use vzalloc() to allocate the buffer. Therefore, we use differnet functions to allocate the buffer for ELF note segment. To avoid code duplication, introduce a helper alloc_elfnotes_buf(). Signed-off-by: HATAYAMA Daisuke <d.hatayama@xxxxxxxxxxxxxx> Reported-by: Arnd Bergmann <arnd@xxxxxxxx> Cc: Atsushi Kumagai <kumagai-atsushi@xxxxxxxxxxxxxxxxx> Cc: HATAYAMA Daisuke <d.hatayama@xxxxxxxxxxxxxx> Cc: KOSAKI Motohiro <kosaki.motohiro@xxxxxxxxxxxxxx> Cc: Lisa Mitchell <lisa.mitchell@xxxxxx> Cc: Vivek Goyal <vgoyal@xxxxxxxxxx> Cc: Zhang Yanfei <zhangyanfei@xxxxxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- fs/proc/vmcore.c | 57 +++++++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 20 deletions(-) diff -puN fs/proc/vmcore.c~vmcore-support-mmap-on-proc-vmcore-fix-2 fs/proc/vmcore.c --- a/fs/proc/vmcore.c~vmcore-support-mmap-on-proc-vmcore-fix-2 +++ a/fs/proc/vmcore.c @@ -195,6 +195,35 @@ static ssize_t read_vmcore(struct file * return acc; } +/** + * alloc_elfnotes_buf - allocate buffer for ELF note segment in + * vmalloc memory + * + * @notes_sz: size of buffer + * + * If CONFIG_MMU is defined, use vmalloc_user() to allow users to mmap + * the buffer to user-space by means of remap_vmalloc_range(). + * + * If CONFIG_MMU is not defined, use vzalloc() since mmap_vmcore() is + * disabled and there's no need to allow users to mmap the buffer. + */ +static inline char *alloc_elfnotes_buf(size_t notes_sz) +{ +#ifdef CONFIG_MMU + return vmalloc_user(notes_sz); +#else + return vzalloc(notes_sz); +#endif +} + +/* + * Disable mmap_vmcore() if CONFIG_MMU is not defined. MMU is + * essential for mmap_vmcore() in order to map physically + * non-contiguous objects (ELF header, ELF note segment and memory + * regions in the 1st kernel pointed to by PT_LOAD entries) into + * virtually contiguous user-space in ELF layout. + */ +#ifdef CONFIG_MMU static int mmap_vmcore(struct file *file, struct vm_area_struct *vma) { size_t size = vma->vm_end - vma->vm_start; @@ -271,6 +300,12 @@ fail: do_munmap(vma->vm_mm, vma->vm_start, len); return -EAGAIN; } +#else +static int mmap_vmcore(struct file *file, struct vm_area_struct *vma) +{ + return -ENOSYS; +} +#endif static const struct file_operations proc_vmcore_operations = { .read = read_vmcore, @@ -427,7 +462,6 @@ static int __init merge_note_headers_elf Elf64_Ehdr *ehdr_ptr; Elf64_Phdr phdr; u64 phdr_sz = 0, note_off; - struct vm_struct *vm; ehdr_ptr = (Elf64_Ehdr *)elfptr; @@ -440,18 +474,10 @@ static int __init merge_note_headers_elf return rc; *notes_sz = roundup(phdr_sz, PAGE_SIZE); - *notes_buf = vzalloc(*notes_sz); + *notes_buf = alloc_elfnotes_buf(*notes_sz); if (!*notes_buf) return -ENOMEM; - /* - * Allow users to remap ELF note segment buffer on vmalloc memory using - * remap_vmalloc_range.() - */ - vm = find_vm_area(*notes_buf); - BUG_ON(!vm); - vm->flags |= VM_USERMAP; - rc = copy_notes_elf64(ehdr_ptr, *notes_buf); if (rc < 0) return rc; @@ -615,7 +641,6 @@ static int __init merge_note_headers_elf Elf32_Ehdr *ehdr_ptr; Elf32_Phdr phdr; u64 phdr_sz = 0, note_off; - struct vm_struct *vm; ehdr_ptr = (Elf32_Ehdr *)elfptr; @@ -628,18 +653,10 @@ static int __init merge_note_headers_elf return rc; *notes_sz = roundup(phdr_sz, PAGE_SIZE); - *notes_buf = vzalloc(*notes_sz); + *notes_buf = alloc_elfnotes_buf(*notes_sz); if (!*notes_buf) return -ENOMEM; - /* - * Allow users to remap ELF note segment buffer on vmalloc memory using - * remap_vmalloc_range() - */ - vm = find_vm_area(*notes_buf); - BUG_ON(!vm); - vm->flags |= VM_USERMAP; - rc = copy_notes_elf32(ehdr_ptr, *notes_buf); if (rc < 0) return rc; _ Patches currently in -mm which might be from d.hatayama@xxxxxxxxxxxxxx are include-linux-mmh-add-page_aligned-helper.patch vmcore-clean-up-read_vmcore.patch vmcore-allocate-buffer-for-elf-headers-on-page-size-alignment.patch vmcore-allocate-buffer-for-elf-headers-on-page-size-alignment-fix.patch vmcore-treat-memory-chunks-referenced-by-pt_load-program-header-entries-in-page-size-boundary-in-vmcore_list.patch vmalloc-make-find_vm_area-check-in-range.patch vmalloc-introduce-remap_vmalloc_range_partial.patch vmalloc-introduce-remap_vmalloc_range_partial-fix.patch vmcore-allocate-elf-note-segment-in-the-2nd-kernel-vmalloc-memory.patch vmcore-allocate-elf-note-segment-in-the-2nd-kernel-vmalloc-memory-fix.patch vmcore-allow-user-process-to-remap-elf-note-segment-buffer.patch vmcore-allow-user-process-to-remap-elf-note-segment-buffer-fix.patch vmcore-calculate-vmcore-file-size-from-buffer-size-and-total-size-of-vmcore-objects.patch vmcore-support-mmap-on-proc-vmcore.patch vmcore-support-mmap-on-proc-vmcore-fix.patch vmcore-support-mmap-on-proc-vmcore-fix-2.patch -- To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html