public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@elte.hu>
To: levinsasha928@gmail.com
Cc: penberg@kernel.org, asias.hejun@gmail.com,
	prasadjoshi124@gmail.com, avi@redhat.com, gorcunov@gmail.com,
	kvm@vger.kernel.org
Subject: Re: [PATCH 1/3 V4] kvm tools: Add memory gap for larger RAM sizes
Date: Wed, 11 May 2011 17:30:15 +0200	[thread overview]
Message-ID: <20110511153015.GC21707@elte.hu> (raw)
In-Reply-To: <4dcaa893.5925e30a.0f9e.125c@mx.google.com>


* levinsasha928@gmail.com <levinsasha928@gmail.com> wrote:

> @@ -225,7 +266,18 @@ struct kvm *kvm__init(const char *kvm_dev, unsigned long ram_size)
>  
>  	self->ram_size		= ram_size;
>  
> -	self->ram_start = mmap(NULL, ram_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0);
> +	if (self->ram_size < KVM_32BIT_GAP_START) {
> +		self->ram_start = mmap(NULL, ram_size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0);
> +	} else {
> +		self->ram_start = mmap(NULL, ram_size + KVM_32BIT_GAP_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0);
> +		if (self->ram_start != MAP_FAILED) {
> +			/*
> +			 * We mprotect the gap (see kvm__init_ram() for details) PROT_NONE so that
> +			 * if we accidently write to it, we will know.
> +			 */
> +			mprotect(self->ram_start + KVM_32BIT_GAP_START, KVM_32BIT_GAP_SIZE, PROT_NONE);

Nit: the mmaps here wrap off the end of line. It would be a lot more easier to 
read if kvm.h defined two helpers, like:

	#define PROT_RW		(PROT_READ|PROT_WRITE)
	#define MAP_ANON	(MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE)

So the mmaps() would become a bit more readable:

> +	if (self->ram_size < KVM_32BIT_GAP_START) {
> +		self->ram_start = mmap(NULL, ram_size, PROT_RW, MAP_ANON, -1, 0);
> +	} else {
> +		self->ram_start = mmap(NULL, ram_size + KVM_32BIT_GAP_SIZE, PROT_RW, MAP_ANON, -1, 0);
> +		if (self->ram_start != MAP_FAILED) {
> +			/*
> +			 * We mprotect the gap (see kvm__init_ram() for details) PROT_NONE so that
> +			 * if we accidently write to it, we will know.
> +			 */
> +			mprotect(self->ram_start + KVM_32BIT_GAP_START, KVM_32BIT_GAP_SIZE, PROT_NONE);

I'll test your series.

Thanks,

	Ingo

  reply	other threads:[~2011-05-11 16:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-11 15:17 [PATCH 1/3 V4] kvm tools: Add memory gap for larger RAM sizes levinsasha928
2011-05-11 15:30 ` Ingo Molnar [this message]
2011-05-11 15:34   ` Ingo Molnar
2011-05-11 15:53     ` Pekka Enberg
2011-05-12  0:49 ` Asias He
2011-05-12  7:34   ` Ingo Molnar

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=20110511153015.GC21707@elte.hu \
    --to=mingo@elte.hu \
    --cc=asias.hejun@gmail.com \
    --cc=avi@redhat.com \
    --cc=gorcunov@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=levinsasha928@gmail.com \
    --cc=penberg@kernel.org \
    --cc=prasadjoshi124@gmail.com \
    /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