From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752538AbbE0VEL (ORCPT ); Wed, 27 May 2015 17:04:11 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:57391 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751486AbbE0VEH (ORCPT ); Wed, 27 May 2015 17:04:07 -0400 Date: Wed, 27 May 2015 14:04:06 -0700 From: Andrew Morton To: Joe Perches Cc: LKML Subject: Re: [RFC patch] vsprintf: Add %pav extension for print_vma_addr Message-Id: <20150527140406.bcc33ecc79da09ad6782b971@linux-foundation.org> In-Reply-To: <1432681504.2846.116.camel@perches.com> References: <1432681504.2846.116.camel@perches.com> X-Mailer: Sylpheed 3.4.1 (GTK+ 2.24.23; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 26 May 2015 16:05:04 -0700 Joe Perches 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; > +} > > ... >