From mboxrd@z Thu Jan 1 00:00:00 1970 From: Avi Kivity Subject: Re: [PATCH] kvm tools: mmap guest kernel instead of reading it into memory Date: Mon, 12 Dec 2011 20:03:22 +0200 Message-ID: <4EE641EA.1000308@redhat.com> References: <1323701258-17443-1-git-send-email-levinsasha928@gmail.com> <1323713645.3269.6.camel@lappy> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Cc: Pekka Enberg , mingo@elte.hu, gorcunov@gmail.com, asias.hejun@gmail.com, kvm@vger.kernel.org, ajsween@sandia.gov To: Sasha Levin Return-path: Received: from mx1.redhat.com ([209.132.183.28]:30864 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752129Ab1LLSDl (ORCPT ); Mon, 12 Dec 2011 13:03:41 -0500 In-Reply-To: <1323713645.3269.6.camel@lappy> Sender: kvm-owner@vger.kernel.org List-ID: 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 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 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 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