mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andi Kleen <ak@suse.de>
To: "Jan Beulich" <jbeulich@novell.com>,
	patches@x86-64.org, linux-kernel@vger.kernel.org
Subject: [PATCH] [6/26] x86: fix amd64-agp aperture validation
Date: Mon, 30 Apr 2007 01:46:15 +0200 (CEST)	[thread overview]
Message-ID: <20070429234615.1B9EB151D2@wotan.suse.de> (raw)
In-Reply-To: <20070430146.588463000@suse.de>


From: "Jan Beulich" <jbeulich@novell.com>
Under CONFIG_DISCONTIGMEM, assuming that a !pfn_valid() implies all
subsequent pfn-s are also invalid is wrong. Thus replace this by
explicitly checking against the E820 map.

AK: make e820 on x86-64 not initdata

Signed-off-by: Jan Beulich <jbeulich@novell.com>
Signed-off-by: Andi Kleen <ak@suse.de>
Acked-by: Mark Langsdorf <mark.langsdorf@amd.com>

---
 arch/i386/kernel/e820.c      |   20 ++++++++++++++++++++
 arch/x86_64/kernel/e820.c    |    5 +++--
 drivers/char/agp/amd64-agp.c |   13 ++++---------
 include/asm-i386/e820.h      |    1 +
 4 files changed, 28 insertions(+), 11 deletions(-)

Index: linux/arch/i386/kernel/e820.c
===================================================================
--- linux.orig/arch/i386/kernel/e820.c
+++ linux/arch/i386/kernel/e820.c
@@ -825,6 +825,26 @@ void __init limit_regions(unsigned long 
 	print_memory_map("limit_regions endfunc");
 }
 
+/*
+ * This function checks if any part of the range <start,end> is mapped
+ * with type.
+ */
+int
+e820_any_mapped(u64 start, u64 end, unsigned type)
+{
+	int i;
+	for (i = 0; i < e820.nr_map; i++) {
+		const struct e820entry *ei = &e820.map[i];
+		if (type && ei->type != type)
+			continue;
+		if (ei->addr >= end || ei->addr + ei->size <= start)
+			continue;
+		return 1;
+	}
+	return 0;
+}
+EXPORT_SYMBOL_GPL(e820_any_mapped);
+
  /*
   * This function checks if the entire range <start,end> is mapped with type.
   *
Index: linux/arch/x86_64/kernel/e820.c
===================================================================
--- linux.orig/arch/x86_64/kernel/e820.c
+++ linux/arch/x86_64/kernel/e820.c
@@ -25,7 +25,7 @@
 #include <asm/bootsetup.h>
 #include <asm/sections.h>
 
-struct e820map e820 __initdata;
+struct e820map e820;
 
 /* 
  * PFN of last memory page.
@@ -98,7 +98,7 @@ static inline int bad_addr(unsigned long
  * This function checks if any part of the range <start,end> is mapped
  * with type.
  */
-int __meminit
+int
 e820_any_mapped(unsigned long start, unsigned long end, unsigned type)
 { 
 	int i;
@@ -112,6 +112,7 @@ e820_any_mapped(unsigned long start, uns
 	} 
 	return 0;
 }
+EXPORT_SYMBOL_GPL(e820_any_mapped);
 
 /*
  * This function checks if the entire range <start,end> is mapped with type.
Index: linux/drivers/char/agp/amd64-agp.c
===================================================================
--- linux.orig/drivers/char/agp/amd64-agp.c
+++ linux/drivers/char/agp/amd64-agp.c
@@ -14,6 +14,7 @@
 #include <linux/agp_backend.h>
 #include <linux/mmzone.h>
 #include <asm/page.h>		/* PAGE_SIZE */
+#include <asm/e820.h>
 #include <asm/k8.h>
 #include "agp.h"
 
@@ -259,7 +260,6 @@ static const struct agp_bridge_driver am
 /* Some basic sanity checks for the aperture. */
 static int __devinit aperture_valid(u64 aper, u32 size)
 {
-	u32 pfn, c;
 	if (aper == 0) {
 		printk(KERN_ERR PFX "No aperture\n");
 		return 0;
@@ -272,14 +272,9 @@ static int __devinit aperture_valid(u64 
 		printk(KERN_ERR PFX "Aperture out of bounds\n");
 		return 0;
 	}
-	pfn = aper >> PAGE_SHIFT;
-	for (c = 0; c < size/PAGE_SIZE; c++) {
-		if (!pfn_valid(pfn + c))
-			break;
-		if (!PageReserved(pfn_to_page(pfn + c))) {
-			printk(KERN_ERR PFX "Aperture pointing to RAM\n");
-			return 0;
-		}
+	if (e820_any_mapped(aper, aper + size, E820_RAM)) {
+		printk(KERN_ERR PFX "Aperture pointing to RAM\n");
+		return 0;
 	}
 
 	/* Request the Aperture. This catches cases when someone else
Index: linux/include/asm-i386/e820.h
===================================================================
--- linux.orig/include/asm-i386/e820.h
+++ linux/include/asm-i386/e820.h
@@ -38,6 +38,7 @@ extern struct e820map e820;
 
 extern int e820_all_mapped(unsigned long start, unsigned long end,
 			   unsigned type);
+extern int e820_any_mapped(u64 start, u64 end, unsigned type);
 extern void find_max_pfn(void);
 extern void register_bootmem_low_pages(unsigned long max_low_pfn);
 extern void e820_register_memory(void);

  parent reply	other threads:[~2007-04-29 23:51 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-29 23:46 [PATCH] [0/26] x86 candidate patches for review IV: more misc patches Andi Kleen
2007-04-29 23:46 ` [PATCH] [1/26] i386: Add smp_ops interface Andi Kleen
2007-04-29 23:46 ` [PATCH] [2/26] i386: Add machine_ops interface to abstract halting and rebooting Andi Kleen
2007-04-29 23:46 ` [PATCH] [4/26] i386: Remove unneeded externs in nmi.c Andi Kleen
2007-04-29 23:46 ` Andi Kleen [this message]
2007-04-29 23:46 ` [PATCH] [7/26] x86_64: Use X86_EFLAGS_IF in x86-64/irqflags.h Andi Kleen
2007-04-29 23:46 ` [PATCH] [8/26] x86_64: fix arithmetic in comment Andi Kleen
2007-04-29 23:46 ` [PATCH] [9/26] x86_64: Fix vmalloc_32 to really allocate <4GB on 64bit platforms Andi Kleen
2007-04-30  5:01   ` Borislav Petkov
2007-04-30  5:49     ` Borislav Petkov
2007-04-30  8:59     ` Andi Kleen
2007-04-29 23:46 ` [PATCH] [10/26] i386: Clean up asm-i386/bugs.h Andi Kleen
2007-04-29 23:46 ` [PATCH] [11/26] i386: clean up identify_cpu Andi Kleen
2007-04-29 23:46 ` [PATCH] [14/26] x86_64: Clean up asm-x86_64/bugs.h Andi Kleen
2007-04-29 23:46 ` [PATCH] [15/26] x86: Don't use MWAIT on AMD Family 10 Andi Kleen
2007-04-29 23:46 ` [PATCH] [16/26] i386: Enable machine check for " Andi Kleen
2007-04-29 23:46 ` [PATCH] [17/26] i386: Use menuconfig objects - APM Andi Kleen
2007-04-29 23:46 ` [PATCH] [18/26] i386: Update smp_call_function* comments Andi Kleen
2007-04-29 23:46 ` [PATCH] [19/26] i386: Enable bank 0 on non K7 Athlon Andi Kleen
2007-04-30  0:09   ` Dave Jones
2007-04-29 23:46 ` [PATCH] [20/26] x86: Allow percpu variables to be page-aligned Andi Kleen
2007-04-29 23:46 ` [PATCH] [21/26] x86: Clean up x86 control register and MSR macros (corrected) Andi Kleen
2007-04-29 23:46 ` [PATCH] [22/26] i386: Remove smp_alt_instructions Andi Kleen
2007-04-29 23:46 ` [PATCH] [23/26] i386: Allow boot-time disable of SMP altinstructions Andi Kleen
2007-04-29 23:46 ` [PATCH] [24/26] x86_64: Fix x86_64 compilation with DEBUG_SIG on Andi Kleen
2007-04-29 23:46 ` [PATCH] [25/26] x86_64: x86-64 system crashes when no memory populating Node 0 Andi Kleen
2007-04-29 23:46 ` [PATCH] [26/26] i386: i386 separate hardware-defined TSS from Linux additions Andi Kleen

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=20070429234615.1B9EB151D2@wotan.suse.de \
    --to=ak@suse.de \
    --cc=jbeulich@novell.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=patches@x86-64.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

Powered by JetHome