All of lore.kernel.org
 help / color / mirror / Atom feed
From: Olaf Hering <olaf@aepfle.de>
To: Ian Campbell <Ian.Campbell@citrix.com>,
	Jan Beulich <JBeulich@suse.com>,
	Ian Jackson <Ian.Jackson@eu.citrix.com>
Cc: xen-devel@lists.xenproject.org,
	"Luis R. Rodriguez" <mcgrof@do-not-panic.com>
Subject: Re: [PATCH] libxc: check return values on mmap() and madvise() on xc_alloc_hypercall_buffer()
Date: Fri, 19 Dec 2014 18:22:34 +0100	[thread overview]
Message-ID: <20141219172234.GA14608@aepfle.de> (raw)
In-Reply-To: <1400678869.4856.88.camel@kazak.uk.xensource.com>

Please backport this patch to 4.4. 
Other branches may need the mmap() check as well. The callers expect
either NULL or a valid pointer.

It is upstream commit e86539a388314cd3dca88f5e69d7873343197cd8

Thanks,

Olaf

On Wed, May 21, Ian Campbell wrote:

> On Tue, 2014-05-20 at 05:37 -0700, Luis R. Rodriguez wrote:
> > From: "Luis R. Rodriguez" <mcgrof@suse.com>
> > 
> > On a Thinkpad T4440p with OpenSUSE tumbleweed with v3.15-rc4
> > and today's latest xen tip from the git tree strace -f reveals
> > we end up on a never ending wait shortly after
> > 
> > write(20, "backend/console/5\0", 18 <unfinished ...>
> > 
> > This is right before we just wait on the qemu process which we
> > had mmap'd for. Without this you'll end up getting stuck on a
> > loop if mmap() worked but madvise() did not. While at it I noticed
> > even the mmap() error fail was not being checked, fix that too.
> > 
> > Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com>
> 
> Acked-by: Ian Campbell <ian.campbell@citrix.com> and applied.
> 
> OOI why was madvise failing? (should be quite unusual I think?)
> 
> > ---
> >  tools/libxc/xc_linux_osdep.c | 20 +++++++++++++++++++-
> >  1 file changed, 19 insertions(+), 1 deletion(-)
> > 
> > diff --git a/tools/libxc/xc_linux_osdep.c b/tools/libxc/xc_linux_osdep.c
> > index 73860a2..86bff3e 100644
> > --- a/tools/libxc/xc_linux_osdep.c
> > +++ b/tools/libxc/xc_linux_osdep.c
> > @@ -92,14 +92,32 @@ static void *linux_privcmd_alloc_hypercall_buffer(xc_interface *xch, xc_osdep_ha
> >  {
> >      size_t size = npages * XC_PAGE_SIZE;
> >      void *p;
> > +    int rc, saved_errno;
> >  
> >      /* Address returned by mmap is page aligned. */
> >      p = mmap(NULL, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS|MAP_LOCKED, -1, 0);
> > +    if ( p == MAP_FAILED )
> > +    {
> > +        PERROR("xc_alloc_hypercall_buffer: mmap failed");
> > +        return NULL;
> > +    }
> >  
> >      /* Do not copy the VMA to child process on fork. Avoid the page being COW
> >          on hypercall. */
> > -    madvise(p, npages * XC_PAGE_SIZE, MADV_DONTFORK);
> > +    rc = madvise(p, npages * XC_PAGE_SIZE, MADV_DONTFORK);
> > +    if ( rc < 0 )
> > +    {
> > +        PERROR("xc_alloc_hypercall_buffer: madvise failed");
> > +        goto out;
> > +    }
> > +
> >      return p;
> > +
> > +out:
> > +    saved_errno = errno;
> > +    (void)munmap(p, size);
> > +    errno = saved_errno;
> > +    return NULL;
> >  }
> >  
> >  static void linux_privcmd_free_hypercall_buffer(xc_interface *xch, xc_osdep_handle h, void *ptr, int npages)

      parent reply	other threads:[~2014-12-19 17:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-20 12:37 [PATCH] libxc: check return values on mmap() and madvise() on xc_alloc_hypercall_buffer() Luis R. Rodriguez
2014-05-21 13:27 ` Ian Campbell
2014-05-21 16:05   ` Luis R. Rodriguez
2014-12-19 17:22   ` Olaf Hering [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20141219172234.GA14608@aepfle.de \
    --to=olaf@aepfle.de \
    --cc=Ian.Campbell@citrix.com \
    --cc=Ian.Jackson@eu.citrix.com \
    --cc=JBeulich@suse.com \
    --cc=mcgrof@do-not-panic.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.