Re: [RFC patch] vsprintf: Add %pav extension for print_vma_addr

From: Andrew Morton
Date: Mon Jun 01 2015 - 19:36:46 EST


On Sun, 31 May 2015 10:51:17 -0700 Joe Perches <joe@xxxxxxxxxxx> wrote:

> On Wed, 2015-05-27 at 14:19 -0700, Andrew Morton wrote:
> > On Wed, 27 May 2015 14:09:31 -0700 Joe Perches <joe@xxxxxxxxxxx> wrote:
> >
> > > > 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.
> > >
> > > This code is basically a copy of the existing print_vma_addr()
> > > so is that true for all the existing uses too?
> >
> > Yeah, the current code is pretty junky. But normally print_vma_addr()
> > should never be called so nobody noticed...
> >
> > In e8bff74a Ingo did a fiddle to preempt_conditional_sti() which looks
> > like it will address the CONFIG_PREEMPT=n issue, but only on x86.
>
> Maybe this? (using GFP_ATOMIC and __GFP_NOWARN)

(tries to remember what this is about)

Please do include the (updated) changelog each time.

This is intended to replace open-coded calls to print_vma_addr(), yes?

We shouldn't really need the memory allocation at all - we could poke
these characters one at a time into the log buffer. That would require
quite some hackery with d_path which would be rather pointless. Maybe
for this purpose it's sufficient to just grab
vma->vm_file->f_path->dentry->d_name. It's not as if this is terribly
important code.

But we still have the down_read(mmap_sem) in there. I don't
immediately see any deadlocks in the current callsites but it isn't
obvious.

I dunno, I just don't think it's a nice idea to be allocating memory
and taking mmap_sem and doing rcu_read_lock (in d_path) all within core
vsprintf/printk. printk() is supposed to be callable from virtually
any context, not "any context as long as you don't use features X Y and
Z".

If we can make print_vma_addr() robust then OK. Perhaps we just don't
try to print the vma's filename. People can look up the hex address in
/proc/pid/maps if it's really needed.

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/