Messages in this thread | | | Date | Wed, 27 May 2015 14:04:06 -0700 | From | Andrew Morton <> | Subject | Re: [RFC patch] vsprintf: Add %pav extension for print_vma_addr |
| |
On Tue, 26 May 2015 16:05:04 -0700 Joe Perches <joe@perches.com> wrote:
> print_vma_addr is another function to emit useful > data similar to print_symbol. The print_symbol > functionality has been added via %p[fFsS] vsprintf > extensions. > > Perhaps it's appropriate to add vma_addr address > decoding to vsprintf too. > > This would allow code conversions where the very > unlikely interleaving of messages from multiple > threads might occur. > > like arch/x86/kernel/traps.c: > > from: > if (show_unhandled_signals && unhandled_signal(tsk, signr) && > printk_ratelimit()) { > pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx", > tsk->comm, tsk->pid, str, > regs->ip, regs->sp, error_code); > print_vma_addr(" in ", regs->ip); > pr_cont("\n"); > to: > pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx in %pav\n", > regs->ip, regs->sp, error_code, ®s->ip); > } > > Something like: > > ... > > @@ -1313,23 +1313,70 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr, > } > > static noinline_for_stack > +char *vma_addr(char *buf, char *end, const void *addr, > + struct printf_spec spec, const char *fmt) > +{ > + struct mm_struct *mm = current->mm; > + struct vm_area_struct *vma; > + unsigned long ip = *(unsigned long *)addr; > + char *rtn; > + > + /* if we are in atomic contexts (in exception stacks, etc.) */ > + if (preempt_count()) > + return string(buf, end, "(atomic context)", spec);
Problems when CONFIG_PREEMPT=n.
> + down_read(&mm->mmap_sem); > + vma = find_vma(mm, ip); > + if (vma && vma->vm_file) { > + struct file *f = vma->vm_file; > + char *gfp_buf = (char *)__get_free_page(GFP_KERNEL);
We shouldn't assume we can use GFP_KERNEL here. Even if the preempt_count() worked, we might be in a context which requires GFP_NOFS or GFP_NOIO.
> + if (gfp_buf) { > + char *p = d_path(&f->f_path, gfp_buf, PAGE_SIZE); > + > + if (IS_ERR(p)) > + p = "?"; > + > + rtn = buf + snprintf(buf, end > buf ? end - buf : 0, > + "%s[%lx+%lx]", > + kbasename(p), > + vma->vm_start, > + vma->vm_end - vma->vm_start); > + > + free_page((unsigned long)gfp_buf); > + } else { > + rtn = string(buf, end, "(__get_free_page failed)", spec); > + } > + } else { > + rtn = string(buf, end, "(find_vma failed)", spec); > + } > + > + up_read(&mm->mmap_sem); > + > + return rtn; > +} > > ... >
| |