From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sasha Levin Subject: Re: [PATCH] kvm tools: mmap guest kernel instead of reading it into memory Date: Mon, 12 Dec 2011 20:14:05 +0200 Message-ID: <1323713645.3269.6.camel@lappy> References: <1323701258-17443-1-git-send-email-levinsasha928@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Cc: mingo@elte.hu, gorcunov@gmail.com, asias.hejun@gmail.com, kvm@vger.kernel.org, ajsween@sandia.gov To: Pekka Enberg Return-path: Received: from mail-bw0-f46.google.com ([209.85.214.46]:58280 "EHLO mail-bw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751389Ab1LLQOe (ORCPT ); Mon, 12 Dec 2011 11:14:34 -0500 Received: by bkcjm19 with SMTP id jm19so1606762bkc.19 for ; Mon, 12 Dec 2011 08:14:33 -0800 (PST) In-Reply-To: Sender: kvm-owner@vger.kernel.org List-ID: 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