public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Yinghai Lu <yinghai@kernel.org>
To: "H. Peter Anvin" <hpa@zytor.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
	Ingo Molnar <mingo@elte.hu>, Mikael Pettersson <mikpe@it.uu.se>,
	Matthew Wilcox <matthew@wil.cx>,
	Grant Grundler <grundler@parisc-linux.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	linux-pci@vger.kernel.org
Subject: Re: [BUG 2.6.31-rc1] HIGHMEM64G causes hang in PCI init on 32-bit x86
Date: Tue, 30 Jun 2009 14:50:26 -0700	[thread overview]
Message-ID: <4A4A88A2.7010509@kernel.org> (raw)
In-Reply-To: <4A4A81C9.9070008@zytor.com>

H. Peter Anvin wrote:
> Yinghai Lu wrote:
>> H. Peter Anvin wrote:
>>> Yinghai Lu wrote:
>>>> agreed, that is why we change round_up to take u64.
>>>>
>>> round_up() is a macro, it doesn't "take" anything per se...
>>>
>> i mean
>>  end = roundup(start, ram_alignment(start)) - 1;
>>
>> static u64 ram_alignment(u64 pos)
>>
>> and other calling to round_up
>>
> 
> This is fixing the wrong problem.  Fixing round_up is the right thing,
> not working around its brain damage.
> 

this one ? 

or you want to move round_up/down to include/linux/kernel.h?

[PATCH] x86: add boundary check for 32bit res before expand e820 resource to alignment -v3

fix hang with HIGHMEM_64G and 32bit resource.
according to hpa and Linus, use (resource_size_t)-1 to fend off big ranges.

analyized by hpa

v2: use roundup instead
v3: from HPA update round_up with __type_of__

Reported-and-tested-by: Mikael Pettersson <mikpe@it.uu.se>
Signed-off-by: Yinghai Lu <yinghai@kernel.org>

---
 arch/x86/include/asm/proto.h |    5 +++--
 arch/x86/kernel/e820.c       |   20 ++++++++++++--------
 2 files changed, 15 insertions(+), 10 deletions(-)

Index: linux-2.6/arch/x86/kernel/e820.c
===================================================================
--- linux-2.6.orig/arch/x86/kernel/e820.c
+++ linux-2.6/arch/x86/kernel/e820.c
@@ -1367,9 +1367,9 @@ void __init e820_reserve_resources(void)
 }
 
 /* How much should we pad RAM ending depending on where it is? */
-static unsigned long ram_alignment(resource_size_t pos)
+static u64 ram_alignment(u64 pos)
 {
-	unsigned long mb = pos >> 20;
+	u64 mb = pos >> 20;
 
 	/* To 64kB in the first megabyte */
 	if (!mb)
@@ -1383,6 +1383,8 @@ static unsigned long ram_alignment(resou
 	return 32*1024*1024;
 }
 
+#define MAX_RESOURCE_SIZE ((resource_size_t)-1)
+
 void __init e820_reserve_resources_late(void)
 {
 	int i;
@@ -1400,17 +1402,19 @@ void __init e820_reserve_resources_late(
 	 * avoid stolen RAM:
 	 */
 	for (i = 0; i < e820.nr_map; i++) {
-		struct e820entry *entry = &e820_saved.map[i];
-		resource_size_t start, end;
+		struct e820entry *entry = &e820.map[i];
+		u64 start, end;
 
 		if (entry->type != E820_RAM)
 			continue;
 		start = entry->addr + entry->size;
-		end = round_up(start, ram_alignment(start));
-		if (start == end)
+		end = round_up(start, ram_alignment(start)) - 1;
+		if (end > MAX_RESOURCE_SIZE)
+			end = MAX_RESOURCE_SIZE;
+		if (start > end)
 			continue;
-		reserve_region_with_split(&iomem_resource, start,
-						  end - 1, "RAM buffer");
+		reserve_region_with_split(&iomem_resource, start, end,
+					  "RAM buffer");
 	}
 }
 
Index: linux-2.6/arch/x86/include/asm/proto.h
===================================================================
--- linux-2.6.orig/arch/x86/include/asm/proto.h
+++ linux-2.6/arch/x86/include/asm/proto.h
@@ -22,7 +22,8 @@ extern int reboot_force;
 
 long do_arch_prctl(struct task_struct *task, int code, unsigned long addr);
 
-#define round_up(x, y) (((x) + (y) - 1) & ~((y) - 1))
-#define round_down(x, y) ((x) & ~((y) - 1))
+#define round_up(x, y) ({ __typeof__(x) __mask = (y)-1; \
+			 ((x)+__mask) & ~__mask; })
+#define round_down(x, y) ({ __typeof__(x) __mask = (y)-1; (x) & ~__mask; })
 
 #endif /* _ASM_X86_PROTO_H */

  reply	other threads:[~2009-06-30 21:51 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-26 15:59 [BUG 2.6.31-rc1] HIGHMEM64G causes hang in PCI init on 32-bit x86 Mikael Pettersson
2009-06-27  1:13 ` Mikael Pettersson
2009-06-27  4:25   ` Grant Grundler
2009-06-27  5:31     ` H. Peter Anvin
2009-06-29  2:24       ` Grant Grundler
2009-06-27  9:42     ` Mikael Pettersson
2009-06-27 19:27       ` H. Peter Anvin
2009-06-27 21:34         ` Mikael Pettersson
2009-06-27  4:53   ` H. Peter Anvin
2009-06-27  9:45     ` Mikael Pettersson
2009-06-29  2:29       ` Grant Grundler
2009-06-29  5:00         ` H. Peter Anvin
2009-06-29 11:12           ` Mikael Pettersson
2009-06-29 11:21             ` Matthew Wilcox
2009-06-29 11:57               ` Mikael Pettersson
2009-06-29 18:29                 ` H. Peter Anvin
2009-06-29 22:47                   ` Yinghai Lu
2009-06-29 23:29                     ` Yinghai Lu
2009-06-30  0:27                       ` H. Peter Anvin
2009-06-30  1:14                         ` Yinghai Lu
2009-06-30  1:18                           ` H. Peter Anvin
2009-06-30  1:24                             ` Yinghai Lu
2009-06-30  2:41                               ` H. Peter Anvin
2009-06-30  1:26                           ` Linus Torvalds
2009-06-30  1:41                             ` Yinghai Lu
2009-06-30  8:45                               ` Mikael Pettersson
2009-06-30 14:48                                 ` H. Peter Anvin
2009-06-30 15:00                                   ` Rolf Eike Beer
2009-06-30 18:52                                     ` H. Peter Anvin
2009-06-30 19:33                                   ` Yinghai Lu
2009-06-30 19:44                                     ` H. Peter Anvin
2009-06-30 20:05                                       ` Yinghai Lu
2009-06-30 21:21                                         ` H. Peter Anvin
2009-06-30 21:50                                           ` Yinghai Lu [this message]
2009-06-30 22:10                                             ` Linus Torvalds
2009-06-30 22:30                                               ` Yinghai Lu
2009-06-30 22:51                                                 ` Yinghai Lu
2009-06-30 22:54                                                   ` H. Peter Anvin
2009-06-30 23:00                                                 ` Linus Torvalds
2009-06-30 23:04                                                   ` Linus Torvalds
2009-06-30 23:13                                                     ` Yinghai Lu
2009-06-30 23:19                                                       ` H. Peter Anvin
2009-07-01 19:32                                                         ` [PATCH] x86: add boundary check for 32bit res before expand e820 resource to alignment Yinghai Lu
2009-07-01 19:33                                                           ` [PATCH] fix round_up/down Yinghai Lu
2009-07-01 19:39                                                             ` Joe Perches
2009-07-01 20:02                                                               ` Andrew Morton
2009-07-02 18:10                                                           ` [PATCH] x86: add boundary check for 32bit res before expand e820 resource to alignment -v2 Yinghai Lu
2009-07-03  8:05                                                             ` Ingo Molnar
2009-06-30 23:16                                                   ` [BUG 2.6.31-rc1] HIGHMEM64G causes hang in PCI init on 32-bit x86 H. Peter Anvin
2009-06-30 20:10                                   ` Linus Torvalds
2009-06-30  1:44                             ` H. Peter Anvin
2009-06-30  0:22                     ` H. Peter Anvin
2009-06-27 19:33 ` [tip:x86/urgent] Revert "x86: cap iomem_resource to addressable physical memory" tip-bot for H. Peter Anvin
2009-06-27 21:49   ` Mikael Pettersson
2009-06-27 22:04 ` tip-bot for H. Peter Anvin
2009-06-28  7:39 ` tip-bot for H. Peter Anvin

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=4A4A88A2.7010509@kernel.org \
    --to=yinghai@kernel.org \
    --cc=grundler@parisc-linux.org \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=matthew@wil.cx \
    --cc=mikpe@it.uu.se \
    --cc=mingo@elte.hu \
    --cc=torvalds@linux-foundation.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