kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <levinsasha928@gmail.com>
To: Pekka Enberg <penberg@kernel.org>
Cc: 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:14:05 +0200	[thread overview]
Message-ID: <1323713645.3269.6.camel@lappy> (raw)
In-Reply-To: <CAOJsxLHF2dV0CHbhZ9AoPX77oG414Rx-rwFYmSGzWow13Pwdpg@mail.gmail.com>

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.

-- 

Sasha.


  reply	other threads:[~2011-12-12 16:14 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 [this message]
2011-12-12 18:03     ` Avi Kivity
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=1323713645.3269.6.camel@lappy \
    --to=levinsasha928@gmail.com \
    --cc=ajsween@sandia.gov \
    --cc=asias.hejun@gmail.com \
    --cc=gorcunov@gmail.com \
    --cc=kvm@vger.kernel.org \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).