Skip to contentSkip to conversation

x86, pat: fix reserve_memtype() for legacy 1MB range

PATCH In review Suresh Siddha 4 participants 11 messages Jan 9, 2009 – Jan 19, 2009

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86, pat: fix reserve_memtype() for legacy 1MB range

From: Suresh Siddha <[email protected]>
Subject: x86, pat: fix reserve_memtype() for legacy 1MB range

Thierry Vignaud reported:

Quoted 6 lines

http://bugzilla.kernel.org/show_bug.cgi?id=12372

On P4 with an SiS motherboard (video card is a SiS 651)
X server fails to start with error:
xf86MapVidMem: Could not mmap framebuffer (0x00000000,0x2000) (Invalid argument)

Here X is trying to map first 8KB of memory using /dev/mem. Existing code treats first 0-4KB of memory as non-RAM and 4KB-8KB as RAM. Recent code changes don't allow to map memory with different attributes at the same time.

Fix this by treating the first 1MB legacy region as special and always track the attribute requests with in this region using linear linked list (and don't bother if the range is RAM or non-RAM or mixed)

---

arch/x86/mm/pat.c +14 -5
index 85cbd3c..c959a4d 100644
@@ -333,11 +333,20 @@ int reserve_memtype(u64 start, u64 end, unsigned long req_type,
 					      req_type & _PAGE_CACHE_MASK);
 	}
 
-	is_range_ram = pagerange_is_ram(start, end);
-	if (is_range_ram == 1)
-		return reserve_ram_pages_type(start, end, req_type, new_type);
-	else if (is_range_ram < 0)
-		return -EINVAL;
+	/*
+	 * For legacy reasons, some parts of the physical address range in the
+	 * legacy 1MB region is treated as non-RAM (even when listed as RAM in
+	 * the e820 tables).  So we will track the memory attributes of this
+	 * legacy 1MB region using the linear memtype_list always.
+	 */
+	if (end >= ISA_END_ADDRESS) {
+		is_range_ram = pagerange_is_ram(start, end);
+		if (is_range_ram == 1)
+			return reserve_ram_pages_type(start, end, req_type,
+						      new_type);
+		else if (is_range_ram < 0)
+			return -EINVAL;
+	}
 
 	new  = kmalloc(sizeof(struct memtype), GFP_KERNEL);
 	if (!new)
#1 lore raw
Quoted 6 lines · Suresh Siddha

Here X is trying to map first 8KB of memory using /dev/mem. Existing code treats first 0-4KB of memory as non-RAM and 4KB-8KB as RAM. Recent code changes don't allow to map memory with different attributes at the same time.

Why was 0-4 KB marked as non-RAM? It is most definitely RAM, and should be WB.

-hpa

#2 lore raw
Quoted 10 lines · H. Peter Anvin
Quoted 6 lines · Suresh Siddha

Here X is trying to map first 8KB of memory using /dev/mem. Existing code treats first 0-4KB of memory as non-RAM and 4KB-8KB as RAM. Recent code changes don't allow to map memory with different attributes at the same time.

Why was 0-4 KB marked as non-RAM? It is most definitely RAM, and should be WB.

While in reality it is RAM, we have CONFIG_STRICT_DEVMEM which doesn't allow apps to map RAM pages using /dev/mem. And to allow app's to map the legacy 0-4KB bios data page, we consider it as non-RAM.

thanks,
suresh

#3 lore raw
Quoted 7 lines · Suresh Siddha
Quoted 6 lines · H. Peter Anvin
Quoted 5 lines · Suresh Siddha

Here X is trying to map first 8KB of memory using /dev/mem. Existing code treats first 0-4KB of memory as non-RAM and 4KB-8KB as RAM. Recent code changes don't allow to map memory with different attributes at the same time.

Quoted 6 lines
Quoted 2 lines

Why was 0-4 KB marked as non-RAM? It is most definitely RAM, and should be WB.

While in reality it is RAM, we have CONFIG_STRICT_DEVMEM which doesn't allow apps to map RAM pages using /dev/mem. And to allow app's to map the legacy 0-4KB bios data page, we consider it as non-RAM.

Permission to map and memory type should not be connected. Just to clarify, when mapped, was it still WB?

-hpa

#4 lore raw
Quoted 11 lines · H. Peter Anvin
Quoted 10 lines · Suresh Siddha
Quoted 8 lines · H. Peter Anvin
Quoted 5 lines · Suresh Siddha

Here X is trying to map first 8KB of memory using /dev/mem. Existing code treats first 0-4KB of memory as non-RAM and 4KB-8KB as RAM. Recent code changes don't allow to map memory with different attributes at the same time.

Why was 0-4 KB marked as non-RAM? It is most definitely RAM, and should be WB.

Quoted 6 lines
Quoted 3 lines

While in reality it is RAM, we have CONFIG_STRICT_DEVMEM which doesn't allow apps to map RAM pages using /dev/mem. And to allow app's to map the legacy 0-4KB bios data page, we consider it as non-RAM.

Permission to map and memory type should not be connected. Just to clarify, when mapped, was it still WB?

yes it is. It's just treated and tracked differently.

#5 lore raw
Quoted 3 lines · Suresh Siddha
Quoted 1 line

Permission to map and memory type should not be connected. Just to clarify, when mapped, was it still WB?

yes it is. It's just treated and tracked differently.

OK, cool. Just wanted to check.

-hpa

#6 lore raw
Quoted 7 lines · H. Peter Anvin
Quoted 4 lines · Suresh Siddha
Quoted 2 lines

Permission to map and memory type should not be connected. Just to clarify, when mapped, was it still WB?

yes it is. It's just treated and tracked differently.

OK, cool. Just wanted to check.

ok - i've applied Suresh's fix to tip/x86/urgent, thanks guys!

Ingo

#7 lore raw
In reply to Suresh Siddha
Quoted 9 lines · Suresh Siddha
Quoted 8 lines · H. Peter Anvin
Quoted 6 lines · Suresh Siddha

Here X is trying to map first 8KB of memory using /dev/mem. Existing code treats first 0-4KB of memory as non-RAM and 4KB-8KB as RAM. Recent code changes don't allow to map memory with different attributes at the same time.

Quoted 6 lines
Quoted 2 lines

Why was 0-4 KB marked as non-RAM? It is most definitely RAM, and should be WB.

While in reality it is RAM, we have CONFIG_STRICT_DEVMEM which doesn't allow apps to map RAM pages using /dev/mem. And to allow app's to map the legacy 0-4KB bios data page, we consider it as non-RAM.

Fix config_strict_devmem? Ram is ram, and we should not li for strict_devmem benefit...

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#8 lore raw
Quoted 8 lines · Pavel Machek
Quoted 7 lines · Suresh Siddha
Quoted 6 lines · H. Peter Anvin
Quoted 5 lines · Suresh Siddha

Here X is trying to map first 8KB of memory using /dev/mem. Existing code treats first 0-4KB of memory as non-RAM and 4KB-8KB as RAM. Recent code changes don't allow to map memory with different attributes at the same time.

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines

Why was 0-4 KB marked as non-RAM? It is most definitely RAM, and should be WB.

While in reality it is RAM, we have CONFIG_STRICT_DEVMEM which doesn't allow apps to map RAM pages using /dev/mem. And to allow app's to map the legacy 0-4KB bios data page, we consider it as non-RAM.

Fix config_strict_devmem? Ram is ram, and we should not li for strict_devmem benefit...

*As far as I understand* this is only considered non-RAM for the purpose of strict_devmem?

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
#9 lore raw
Quoted 15 lines · H. Peter Anvin
Quoted 14 lines · Pavel Machek
Quoted 12 lines · Suresh Siddha
Quoted 8 lines · H. Peter Anvin
Quoted 5 lines · Suresh Siddha

Here X is trying to map first 8KB of memory using /dev/mem. Existing code treats first 0-4KB of memory as non-RAM and 4KB-8KB as RAM. Recent code changes don't allow to map memory with different attributes at the same time.

Why was 0-4 KB marked as non-RAM? It is most definitely RAM, and should be WB.

While in reality it is RAM, we have CONFIG_STRICT_DEVMEM which doesn't allow apps to map RAM pages using /dev/mem. And to allow app's to map the legacy 0-4KB bios data page, we consider it as non-RAM.

Quoted 5 lines
Quoted 2 lines

Fix config_strict_devmem? Ram is ram, and we should not li for strict_devmem benefit...

*As far as I understand* this is only considered non-RAM for the purpose of strict_devmem?

I did not look *too* closely, but the patch at the beggining of this thread was for pat.c or something like that. I'd expect it to change /dev/mem code...
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#10 lore raw
In reply to Pavel Machek
Quoted 13 lines · Pavel Machek
Quoted 12 lines · Suresh Siddha
Quoted 10 lines · H. Peter Anvin
Quoted 6 lines · Suresh Siddha

Here X is trying to map first 8KB of memory using /dev/mem. Existing code treats first 0-4KB of memory as non-RAM and 4KB-8KB as RAM. Recent code changes don't allow to map memory with different attributes at the same time.

Why was 0-4 KB marked as non-RAM? It is most definitely RAM, and should be WB.

Quoted 6 lines
Quoted 3 lines

While in reality it is RAM, we have CONFIG_STRICT_DEVMEM which doesn't allow apps to map RAM pages using /dev/mem. And to allow app's to map the legacy 0-4KB bios data page, we consider it as non-RAM.

Fix config_strict_devmem? Ram is ram, and we should not li for strict_devmem benefit...

This is not just related to CONFIG_STRICT_DEVMEM. This is how we track the PAT attribute for this 1MB physical address range even in the case of !CONFIG_STRICT_DEVMEM

In some portions of the x86 code, we treat legacy first 1MB as special. CONFIG_STRICT_DEVMEM is one of them.

For this range, we don't really follow what e820 says about this region. For example, for some of the systems, e820 table doesn't even include some portions of this 1MB region etc.

I looked at including this 1MB check in page_is_ram(). But this routine is called at various generic places (like mem_init() where it really needs to know what e820 says etc).

thanks,
suresh