Re: [PATCH] kvm tools: mmap guest kernel instead of reading it into memory

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 2011-12-12 at 17:59 +0200, Pekka Enberg wrote:
> On Mon, Dec 12, 2011 at 4:47 PM, Sasha Levin <levinsasha928@xxxxxxxxx> 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.

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux