virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Rusty Russell <rusty@rustcorp.com.au>
To: James Morris <jmorris@namei.org>
Cc: lkml - Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Andi Kleen <ak@muc.de>, Andrew Morton <akpm@linux-foundation.org>,
	virtualization <virtualization@lists.osdl.org>
Subject: Re: [PATCH 4 of 7]  lguest: Config and headers
Date: Sat, 10 Feb 2007 20:33:37 +1100	[thread overview]
Message-ID: <1171100017.15356.21.camel@localhost.localdomain> (raw)
In-Reply-To: <Pine.LNX.4.64.0702092243170.13855@d.namei>

On Fri, 2007-02-09 at 22:45 -0500, James Morris wrote:
> On Sat, 10 Feb 2007, Rusty Russell wrote:
> 
> > Well it was the use of get_order() which triggered Andi's alarm bells,
> > so I went back to deriving it.  This code is correct, however.
> 
> +       hype_pages = alloc_pages(GFP_KERNEL|__GFP_ZERO, HYPERVISOR_MAP_ORDER);
> +       if (!hype_pages)
> +               return -ENOMEM;
> 
> This will try and allocate 2^16 pages.  I guess we need a 
> HYPERVISOR_PAGE_ORDER ?

Fuck a brick, you're right.  Worked here tho 8)  There's a moral here
somewhere about futzing with perfectly working code after midnight, I'm
sure.

Name: Don't allocate 2^16 pages in lg.ko

Code cleanup which avoided use of get_order() resulted in a thinko: we
allocated 65536 pages instead of 65536 bytes.  Thanks to James Morris
for pointing this out (twice!).

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>

diff -r 3bcbcc7c7659 arch/i386/lguest/core.c
--- a/arch/i386/lguest/core.c	Sat Feb 10 10:44:25 2007 +1100
+++ b/arch/i386/lguest/core.c	Sat Feb 10 20:26:03 2007 +1100
@@ -24,8 +24,8 @@ static char __initdata hypervisor_blob[]
 #include "hypervisor-blob.c"
 };
 
-#define MAX_LGUEST_GUESTS						\
-	(((1 << HYPERVISOR_MAP_ORDER) - sizeof(hypervisor_blob))	\
+#define MAX_LGUEST_GUESTS						  \
+	(((PAGE_SIZE << HYPERVISOR_PAGE_ORDER) - sizeof(hypervisor_blob)) \
 	 / sizeof(struct lguest_state))
 
 static struct vm_struct *hypervisor_vma;
@@ -62,12 +62,12 @@ static __init int map_hypervisor(void)
 	int err;
 	struct page *pages[HYPERVISOR_PAGES], **pagep = pages;
 
-	hype_pages = alloc_pages(GFP_KERNEL|__GFP_ZERO, HYPERVISOR_MAP_ORDER);
+	hype_pages = alloc_pages(GFP_KERNEL|__GFP_ZERO, HYPERVISOR_PAGE_ORDER);
 	if (!hype_pages)
 		return -ENOMEM;
 
-	hypervisor_vma = __get_vm_area(1 << HYPERVISOR_MAP_ORDER, VM_ALLOC,
-				       HYPE_ADDR, VMALLOC_END);
+	hypervisor_vma = __get_vm_area(PAGE_SIZE << HYPERVISOR_PAGE_ORDER,
+				       VM_ALLOC, HYPE_ADDR, VMALLOC_END);
 	if (!hypervisor_vma) {
 		err = -ENOMEM;
 		printk("lguest: could not map hypervisor pages high\n");
@@ -100,14 +100,14 @@ free_vma:
 free_vma:
 	vunmap(hypervisor_vma->addr);
 free_pages:
-	__free_pages(hype_pages, HYPERVISOR_MAP_ORDER);
+	__free_pages(hype_pages, HYPERVISOR_PAGE_ORDER);
 	return err;
 }
 
 static __exit void unmap_hypervisor(void)
 {
 	vunmap(hypervisor_vma->addr);
-	__free_pages(hype_pages, HYPERVISOR_MAP_ORDER);
+	__free_pages(hype_pages, HYPERVISOR_PAGE_ORDER);
 }
 
 /* IN/OUT insns: enough to get us past boot-time probing. */
diff -r 3bcbcc7c7659 arch/i386/lguest/lg.h
--- a/arch/i386/lguest/lg.h	Sat Feb 10 10:44:25 2007 +1100
+++ b/arch/i386/lguest/lg.h	Sat Feb 10 20:27:54 2007 +1100
@@ -3,8 +3,8 @@
 
 #include <asm/desc.h>
 /* 64k ought to be enough for anybody! */
-#define HYPERVISOR_MAP_ORDER 16
-#define HYPERVISOR_PAGES ((1 << HYPERVISOR_MAP_ORDER)/PAGE_SIZE)
+#define HYPERVISOR_PAGE_ORDER (16 - PAGE_SHIFT)
+#define HYPERVISOR_PAGES (1 << HYPERVISOR_PAGE_ORDER)
 
 #define GDT_ENTRY_LGUEST_CS	10
 #define GDT_ENTRY_LGUEST_DS	11

      reply	other threads:[~2007-02-10  9:33 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-02-09 14:59 [PATCH 0 of 7] lguest host code Rusty Russell
2007-02-09 15:03 ` [PATCH 1 of 7] lguest: Move mce_disabled to asm/mce.h so lguest can use it Rusty Russell
2007-02-09 15:03   ` [PATCH 2 of 7] lguest: Rename cpu_gdt_descr and remove extern declaration from smpboot.c Rusty Russell
2007-02-09 15:04     ` [PATCH 3 of 7] lguest: Remove extern declaration from mm/discontig.c, put in header Rusty Russell
2007-02-09 15:09       ` [PATCH 4 of 7] lguest: Config and headers Rusty Russell
2007-02-09 15:14         ` [PATCH 5 of 7] lguest: the host code (lg.ko) Rusty Russell
2007-02-09 15:17           ` [PATCH 6 of 7] lguest: Guest code Rusty Russell
2007-02-09 15:21             ` [PATCH 7 of 7] lguest: Makefile Rusty Russell
2007-02-09 18:15         ` [PATCH 4 of 7] lguest: Config and headers James Morris
2007-02-09 23:41           ` Rusty Russell
2007-02-10  3:45             ` James Morris
2007-02-10  9:33               ` Rusty Russell [this message]

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=1171100017.15356.21.camel@localhost.localdomain \
    --to=rusty@rustcorp.com.au \
    --cc=ak@muc.de \
    --cc=akpm@linux-foundation.org \
    --cc=jmorris@namei.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=virtualization@lists.osdl.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).