All of lore.kernel.org
 help / color / mirror / Atom feed
From: Avi Kivity <avi@redhat.com>
To: Sasha Levin <levinsasha928@gmail.com>
Cc: Pekka Enberg <penberg@kernel.org>,
	mingo@elte.hu, gorcunov@gmail.com, asias.hejun@gmail.com,
	kvm@vger.kernel.org, ajsween@sandia.gov
Subject: Re: [PATCH] kvm tools: mmap guest kernel instead of reading it into memory
Date: Mon, 12 Dec 2011 20:03:22 +0200	[thread overview]
Message-ID: <4EE641EA.1000308@redhat.com> (raw)
In-Reply-To: <1323713645.3269.6.camel@lappy>

On 12/12/2011 08:14 PM, Sasha Levin wrote:
> On Mon, 2011-12-12 at 17:59 +0200, Pekka Enberg wrote:
> > On Mon, Dec 12, 2011 at 4:47 PM, Sasha Levin <levinsasha928@gmail.com> wrote:
> > > +       /* mmap the actual kernel */
> > > +       kvm->bz_fd = dup(fd_kernel);
> > > +       kvm->bz_len = st.st_size;
> > > +       setup_end = ALIGN(setup_size - PAGE_SIZE, PAGE_SIZE); /* Need it aligned to PAGE_SIZE */
> > > +       kvm->bz_start = mmap(NULL, kvm->bz_len, PROT_READ | PROT_WRITE,
> > > +                               MAP_PRIVATE, kvm->bz_fd, setup_end);
> > >
> > > -       while ((nr = read(fd_kernel, p, 65536)) > 0)
> > > -               p += nr;
> > > +       /* NOP everything before the kernel start */
> > > +       memset(kvm->bz_start, 0x90, setup_size - setup_end);
> > 
> > So what's the deal with this NOP thing? It really needs a comment that
> > explains it all.
>
> Right, I'll explain it here and if it sounds right to you I'll add it
> into the patch.
>
> Since the start of the actual kernel image is somewhere into the
> bzImage, and is not aligned to anything, we can't mmap() directly to the
> beginning of it.
>
> So what we do is mmap the kernel with <PAGE_SIZE bytes before it which
> belong to the setup code.
>
> KVM expects page aligned pointers for both in-guest physical memory
> start, and the corresponding userspace address. This means that we can't
> simply pass an offset within the memory we mapped before since it won't
> be page aligned.
>
> The solution is to NOP the bytes which belong to the setup code right
> before the kernel starts. In practice it means <PAGE_SIZE NOPs before
> actual kernel code starts running.

Can't you just adjust rip to point to the starting code?

-- 
error compiling committee.c: too many arguments to function


  reply	other threads:[~2011-12-12 18:03 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-12 14:47 [PATCH] kvm tools: mmap guest kernel instead of reading it into memory Sasha Levin
2011-12-12 14:54 ` Pekka Enberg
2011-12-12 17:47   ` Sasha Levin
2011-12-12 16:40     ` Andrew Walrond
2011-12-12 15:59 ` Pekka Enberg
2011-12-12 18:14   ` Sasha Levin
2011-12-12 18:03     ` Avi Kivity [this message]
2011-12-12 17:18 ` Ingo Molnar
2011-12-12 18:08 ` Avi Kivity
2011-12-12 18:10 ` Avi Kivity
2011-12-13  6:46   ` Sasha Levin

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=4EE641EA.1000308@redhat.com \
    --to=avi@redhat.com \
    --cc=ajsween@sandia.gov \
    --cc=asias.hejun@gmail.com \
    --cc=gorcunov@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=levinsasha928@gmail.com \
    --cc=mingo@elte.hu \
    --cc=penberg@kernel.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.