Received: from list by lists.gnu.org with archive (Exim 4.71) id 1TMxIR-0000k0-Rf for mharc-grub-devel@gnu.org; Sat, 13 Oct 2012 04:42:11 -0400 Received: from eggs.gnu.org ([208.118.235.92]:47289) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TMxIP-0000jt-9c for grub-devel@gnu.org; Sat, 13 Oct 2012 04:42:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TMxIM-0008Fv-Rs for grub-devel@gnu.org; Sat, 13 Oct 2012 04:42:09 -0400 Received: from chiark.greenend.org.uk ([212.13.197.229]:48344) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TMxIM-0008Fq-MO for grub-devel@gnu.org; Sat, 13 Oct 2012 04:42:06 -0400 Received: from [172.20.153.9] (helo=riva.pelham.vpn.ucam.org) by chiark.greenend.org.uk (Debian Exim 4.72 #1) with esmtps (return-path cjwatson@ubuntu.com) id 1TMxIL-0001YT-Q0 for grub-devel@gnu.org; Sat, 13 Oct 2012 09:42:05 +0100 Received: from localhost ([127.0.0.1] helo=sarantium.pelham.vpn.ucam.org) by riva.pelham.vpn.ucam.org with esmtp (Exim 4.72) (envelope-from ) id 1TMxIK-0000pi-QR for grub-devel@gnu.org; Sat, 13 Oct 2012 09:42:04 +0100 Received: from riva.dynamic.greenend.org.uk (localhost [127.0.0.1]) by sarantium.pelham.vpn.ucam.org (Postfix) with ESMTPS id 30AC23E40A0 for ; Sat, 13 Oct 2012 09:41:45 +0100 (BST) Date: Sat, 13 Oct 2012 09:41:43 +0100 From: Colin Watson To: grub-devel@gnu.org Subject: [PATCH] Incorrect initrd minimum address calculation Message-ID: <20121013084143.GM29365@riva.dynamic.greenend.org.uk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 212.13.197.229 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 13 Oct 2012 08:42:10 -0000 One of my colleagues asked me to look into this bug, which showed Ubuntu unable to boot as a guest within Windows Azure: https://bugs.launchpad.net/bugs/1055686 Although there was some speculation that this might be a bug in the virtual hardware platform, I was unconvinced. Debugging output from GRUB indicated that this was a problem with allocating physical memory, and dmesg output from Linux showed that there should have been enough sufficiently low memory for the kernel and initrd. The usable lines from E820 output were: BIOS-e820: [mem 0x0000000000000000-0x000000000009fbff] usable BIOS-e820: [mem 0x0000000000100000-0x0000000003feffff] usable BIOS-e820: [mem 0x0000000040000000-0x00000000abffffff] usable I looked hard at how GRUB allocates memory for the initrd. The maximum address is capped to 0x37FFFFFF, thereby excluding the 0x40000000-0xABFFFFFF range that's available on this system, so the effective available range per E820 data is 0x100000-0x3FEFFFF, minus what's already been allocated for the kernel. The minimum address is then taken as the target physical address of the kernel (here, 0x1000000) plus its required init space (here, 0x134F000) plus the initrd size. But the initrd is going to be allocated *above* this address. Why does it need to add the initrd size? The effect of this calculation is to limit the initrd size to about 15MB when it should be limited to about 30MB. What do you think of this patch? 2012-10-13 Colin Watson * grub-core/loader/i386/linux.c (grub_cmd_initrd): Don't add the initrd size to addr_min, since the initrd will be allocated after this address. === modified file 'grub-core/loader/i386/linux.c' --- grub-core/loader/i386/linux.c 2012-10-05 12:09:19 +0000 +++ grub-core/loader/i386/linux.c 2012-10-13 08:33:56 +0000 @@ -1101,8 +1101,7 @@ grub_cmd_initrd (grub_command_t cmd __at worse than that of Linux 2.3.xx, so avoid the last 64kb. */ addr_max -= 0x10000; - addr_min = (grub_addr_t) prot_mode_target + prot_init_space - + page_align (size); + addr_min = (grub_addr_t) prot_mode_target + prot_init_space; /* Put the initrd as high as possible, 4KiB aligned. */ addr = (addr_max - size) & ~0xFFF; Thanks, -- Colin Watson [cjwatson@ubuntu.com]