Skip to contentSkip to conversation

include/asm-arm/memory.h changes break zaurus sl-5500 boot

PATCH Pavel Machek 3 participants 10 messages Apr 2, 2006 – Apr 3, 2006

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

Hi!

This reverts this (and one more) patch, and fixes boot on collie. Without this patch, I get some fairly strange warnings about shift bigger than page size in pfn_to_page().

Pavel

commit 7eb98a2f3b605d8a11434d855b58d828393ea533
tree 4643bb90d8fe3e48ca8d042286ca3d55b8560d45
parent 1c05dda2b6f025267ab79a267e0a84628a3760e1
author KAMEZAWA Hiroyuki <[email protected]> Mon, 27 Mar 2006 01:15:37 -0800
committer Linus Torvalds <[email protected]> Mon, 27 Mar 2006 08:44:44 -0800

[PATCH] unify pfn_to_page: arm pfn_to_page

ARM can use generic funcs.
PFN_TO_NID, LOCAL_MAP_NR are defined by sub-archs.

include/asm-alpha/mmzone.h +2 -1
index 192d80c..c900439 100644
@@ -83,7 +83,8 @@ PLAT_NODE_DATA_LOCALNR(unsigned long p, 
 	pte_t pte;                                                           \
 	unsigned long pfn;                                                   \
 									     \
-	pfn = page_to_pfn(page) << 32; \
+	pfn = ((unsigned long)((page)-page_zone(page)->zone_mem_map)) << 32; \
+	pfn += page_zone(page)->zone_start_pfn << 32;			     \
 	pte_val(pte) = pfn | pgprot_val(pgprot);			     \
 									     \
 	pte;								     \
include/asm-arm/memory.h +10 -5
index afa5c3e..b4e1146 100644
@@ -172,7 +172,9 @@ static inline __deprecated void *bus_to_
  *  virt_addr_valid(k)	indicates whether a virtual address is valid
  */
 #ifndef CONFIG_DISCONTIGMEM
-#define ARCH_PFN_OFFSET		(PHYS_PFN_OFFSET)
+
+#define page_to_pfn(page)	(((page) - mem_map) + PHYS_PFN_OFFSET)
+#define pfn_to_page(pfn)	((mem_map + (pfn)) - PHYS_PFN_OFFSET)
 #define pfn_valid(pfn)		((pfn) >= PHYS_PFN_OFFSET && (pfn) < (PHYS_PFN_OFFSET + max_mapnr))
 
 #define virt_to_page(kaddr)	(pfn_to_page(__pa(kaddr) >> PAGE_SHIFT))
@@ -187,8 +189,13 @@ static inline __deprecated void *bus_to_
  * around in memory.
  */
 #include <linux/numa.h>
-#define arch_pfn_to_nid(pfn)	(PFN_TO_NID(pfn))
-#define arch_local_page_offset(pfn, nid) (LOCAL_MAP_NR((pfn) << PAGE_OFFSET))
+
+#define page_to_pfn(page)					\
+	(( (page) - page_zone(page)->zone_mem_map)		\
+	  + page_zone(page)->zone_start_pfn)
+
+#define pfn_to_page(pfn)					\
+	(PFN_TO_MAPBASE(pfn) + LOCAL_MAP_NR((pfn) << PAGE_SHIFT))
 
 #define pfn_valid(pfn)						\
 	({							\
@@ -236,6 +243,4 @@ static inline __deprecated void *bus_to_
 
 #endif
 
-#include <asm-generic/memory_model.h>
-
 #endif
include/asm-generic/memory_model.h +5 -5
index 0cfb086..a7bb497 100644
@@ -45,11 +45,11 @@ extern unsigned long page_to_pfn(struct 
 	NODE_DATA(__nid)->node_mem_map + arch_local_page_offset(__pfn, __nid);\
 })
 
-#define page_to_pfn(pg)							\
-({	struct page *__pg = (pg);					\
-	struct pglist_data *__pgdat = NODE_DATA(page_to_nid(__pg));	\
-	(unsigned long)(__pg - __pgdat->node_mem_map) +			\
-	 __pgdat->node_start_pfn;					\
+#define page_to_pfn(pg)			\
+({	struct page *__pg = (pg);		\
+	struct zone *__zone = page_zone(__pg);	\
+	(unsigned long)(__pg - __zone->zone_mem_map) +	\
+	 __zone->zone_start_pfn;			\
 })
 
 #elif defined(CONFIG_SPARSEMEM)
include/linux/mmzone.h +1 -0
index b5c2112..9d2b23e 100644
@@ -226,6 +226,7 @@ struct zone {
 	 * Discontig memory support fields.
 	 */
 	struct pglist_data	*zone_pgdat;
+	struct page		*zone_mem_map;
 	/* zone_start_pfn == zone_start_paddr >> PAGE_SHIFT */
 	unsigned long		zone_start_pfn;
 
mm/page_alloc.c +4 -2
index dc523a1..519724d 100644
@@ -2041,6 +2041,7 @@ static __meminit void init_currently_emp
 	zone_wait_table_init(zone, size);
 	pgdat->nr_zones = zone_idx(zone) + 1;
 
+	zone->zone_mem_map = pfn_to_page(zone_start_pfn);
 	zone->zone_start_pfn = zone_start_pfn;
 
 	memmap_init(size, pgdat->node_id, zone_idx(zone), zone_start_pfn);
@@ -2767,8 +2768,9 @@ struct page *pfn_to_page(unsigned long p
 }
 unsigned long page_to_pfn(struct page *page)
 {
-	struct pglist_data *pgdat = NODE_DATA(page_to_nid(page));
-	return (page - pgdat->node_mem_map) + pgdat->node_start_pfn;
+	struct zone *zone = page_zone(page);
+	return (page - zone->zone_mem_map) + zone->zone_start_pfn;
+
 }
 #elif defined(CONFIG_SPARSEMEM)
 struct page *pfn_to_page(unsigned long pfn)
Signature · 1 line
Picture of sleeping (Linux) penguin wanted...
#1 lore raw
Quoted 3 lines · Pavel Machek

This reverts this (and one more) patch, and fixes boot on collie. Without this patch, I get some fairly strange warnings about shift bigger than page size in pfn_to_page().

Not surprising given this gem:

Quoted 1 line

-#define arch_local_page_offset(pfn, nid) (LOCAL_MAP_NR((pfn) << PAGE_OFFSET))

PAGE_OFFSET being 3GB - that's one hell of a shift value!

Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core
#2 lore raw
Quoted 10 lines · Russell King
Quoted 3 lines · Pavel Machek

This reverts this (and one more) patch, and fixes boot on collie. Without this patch, I get some fairly strange warnings about shift bigger than page size in pfn_to_page().

Not surprising given this gem:

Quoted 1 line

-#define arch_local_page_offset(pfn, nid) (LOCAL_MAP_NR((pfn) << PAGE_OFFSET))

PAGE_OFFSET being 3GB - that's one hell of a shift value!

Unfortunately this is mainline now. Is there some better fix than simply reverting the offending patches?
Pavel

Signature · 1 line
Picture of sleeping (Linux) penguin wanted...
#3 lore raw
Quoted 6 lines · On Mon, 3 Apr 2006 00:23:14 +0200 Pavel Machek <[email protected]> wrote:
Quoted 5 lines · Russell King
Quoted 3 lines · Pavel Machek

This reverts this (and one more) patch, and fixes boot on collie. Without this patch, I get some fairly strange warnings about shift bigger than page size in pfn_to_page().

Quoted 6 lines
Quoted 5 lines

Not surprising given this gem:

Quoted 1 line

-#define arch_local_page_offset(pfn, nid) (LOCAL_MAP_NR((pfn) << PAGE_OFFSET))

PAGE_OFFSET being 3GB - that's one hell of a shift value!

stupid...PAGE_OFFSET is offset.. not shift.

LOCAL_MAP_NR((pfn) << PAGE_SHIFT) ?? what does file include this ? I'll look into.

- Kame

#4 lore raw
In reply to Pavel Machek
Quoted 8 lines · On Mon, 3 Apr 2006 00:23:14 +0200 Pavel Machek <[email protected]> wrote:
Quoted 5 lines

Not surprising given this gem:

Quoted 1 line

-#define arch_local_page_offset(pfn, nid) (LOCAL_MAP_NR((pfn) << PAGE_OFFSET))

PAGE_OFFSET being 3GB - that's one hell of a shift value!

Unfortunately this is mainline now. Is there some better fix than simply reverting the offending patches?

Maybe this one will fix (against 2.6.16-mm2)

LOCAL_MAP_NR(kaddr) returns page offset in a node.

-Kame
==

include/asm-arm/memory.h +1 -1
Index: linux-2.6.16-mm2/include/asm-arm/memory.h
===================================================================
@@ -188,7 +188,7 @@ static inline __deprecated void *bus_to_
  */
 #include <linux/numa.h>
 #define arch_pfn_to_nid(pfn)	(PFN_TO_NID(pfn))
-#define arch_local_page_offset(pfn, nid) (LOCAL_MAP_NR((pfn) << PAGE_OFFSET))
+#define arch_local_page_offset(pfn, nid) (LOCAL_MAP_NR(__va((pfn) << PAGE_SHIFT)))
 
 #define pfn_valid(pfn)						\
 	({							\
#5 lore raw
Quoted 6 lines · KAMEZAWA Hiroyuki
Quoted 4 lines · On Mon, 3 Apr 2006 00:23:14 +0200 Pavel Machek <[email protected]> wrote:
Quoted 4 lines

Not surprising given this gem:

Quoted 1 line

-#define arch_local_page_offset(pfn, nid) (LOCAL_MAP_NR((pfn) << PAGE_OFFSET))

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

PAGE_OFFSET being 3GB - that's one hell of a shift value!

Unfortunately this is mainline now. Is there some better fix than simply reverting the offending patches?

Maybe this one will fix (against 2.6.16-mm2)

LOCAL_MAP_NR(kaddr) returns page offset in a node.

LOCAL_MAP_NR does not take a kernel virtual address. If you look at how it's defined (Eg):

#define LOCAL_MAP_NR(addr) \
        (((unsigned long)(addr) & 0x07ffffff) >> PAGE_SHIFT)

then you will notice that it's actually converting an offset into a node into an index. This means that converting a PFN to a virtual address is just a complete and utter waste of time.

So:

include/asm-arm/memory.h static inline __deprecated void *bus_to_ · line 191

Quoted 2 lines
include/asm-arm/memory.h +1 -1
-#define arch_local_page_offset(pfn, nid) (LOCAL_MAP_NR((pfn) << PAGE_OFFSET))
+#define arch_local_page_offset(pfn, nid) (LOCAL_MAP_NR(__va((pfn) << PAGE_SHIFT)))

this should be:

#define arch_local_page_offset(pfn, nid) LOCAL_MAP_NR((pfn) << PAGE_SHIFT)

Please also avoid the over-use of parens. It's a disease which just makes things harder to read (eg, the have I got enough close parens at the end of the line to balance.)

Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core
#6 lore raw
Quoted 14 lines · On Mon, 3 Apr 2006 08:36:53 +0100 Russell King <[email protected]>…
Quoted 13 lines · KAMEZAWA Hiroyuki
Quoted 8 lines · On Mon, 3 Apr 2006 00:23:14 +0200 Pavel Machek <[email protected]> wrote:
Quoted 5 lines

Not surprising given this gem:

Quoted 1 line

-#define arch_local_page_offset(pfn, nid) (LOCAL_MAP_NR((pfn) << PAGE_OFFSET))

PAGE_OFFSET being 3GB - that's one hell of a shift value!

Unfortunately this is mainline now. Is there some better fix than simply reverting the offending patches?

Maybe this one will fix (against 2.6.16-mm2)

Quoted 8 lines
Quoted 1 line

LOCAL_MAP_NR(kaddr) returns page offset in a node.

LOCAL_MAP_NR does not take a kernel virtual address. If you look at how it's defined (Eg):

#define LOCAL_MAP_NR(addr) \
        (((unsigned long)(addr) & 0x07ffffff) >> PAGE_SHIFT)

Hmm..from include/asm-arm/arch-clps711x/memory.h

==
/*
* Given a kaddr, LOCAL_MAR_NR finds the owning node of the memory
* and returns the index corresponding to the appropriate page in the
* node's mem_map.
*/

#define LOCAL_MAP_NR(addr) \
        (((unsigned long)(addr) & (NODE_MAX_MEM_SIZE - 1)) >> PAGE_SHIFT)

==

Is this comment wrong ???

I already posted patch against 2.6.17-rc1. so, please NACK for it. sorry for annoying.

Thanks,
-- Kame

#7 lore raw
Quoted 10 lines · On Mon, 3 Apr 2006 16:44:34 +0900 KAMEZAWA Hiroyuki…

On Mon, 3 Apr 2006 08:36:53 +0100
Russell King <[email protected]> wrote:
Hmm..from include/asm-arm/arch-clps711x/memory.h

==
/*
* Given a kaddr, LOCAL_MAR_NR finds the owning node of the memory
* and returns the index corresponding to the appropriate page in the
* node's mem_map.
*/

Quoted 6 lines
#define LOCAL_MAP_NR(addr) \
        (((unsigned long)(addr) & (NODE_MAX_MEM_SIZE - 1)) >> PAGE_SHIFT)

==

Is this comment wrong ???

Russell-san

All of sub-arch's comment says "Given a kaddr" but all of them just uses "offset". So, paddr can be given as arg.
__va()(or pfn_to_kaddr()) adds unnecessary calcs, so paddr should be used instead of kaddr. Right ?

-Kame

#8 lore raw
Quoted 17 lines · KAMEZAWA Hiroyuki
Quoted 14 lines · On Mon, 3 Apr 2006 16:44:34 +0900 KAMEZAWA Hiroyuki…

On Mon, 3 Apr 2006 08:36:53 +0100
Russell King <[email protected]> wrote:
Hmm..from include/asm-arm/arch-clps711x/memory.h

==
/*
* Given a kaddr, LOCAL_MAR_NR finds the owning node of the memory
* and returns the index corresponding to the appropriate page in the
* node's mem_map.
*/

#define LOCAL_MAP_NR(addr) \
        (((unsigned long)(addr) & (NODE_MAX_MEM_SIZE - 1)) >> PAGE_SHIFT)

==

Quoted 1 line
Quoted 1 line

Is this comment wrong ???

The comment isn't entirely accurate.

Quoted 2 lines

All of sub-arch's comment says "Given a kaddr" but all of them just uses "offset". So, paddr can be given as arg.

Yes.

Quoted 2 lines

__va()(or pfn_to_kaddr()) adds unnecessary calcs, so paddr should be used instead of kaddr.

The problem with __va() and pfn_to_kaddr() is that it adds unnecessary calculation which the compiler can not optimise away.

Quoted 1 line

From the use of LOCAL_MAP_NR(), we know that it's returning an offset

into a particular node, and that there's a 1:1 relationship between the virtual and physical addresses within nodes. That means that LOCAL_MAP_NR() can take either a virtual address, a physical address, or even a byte offset into the node.

In turn, that means that we can pass it whatever address we happen to have available at the time, or whichever is simpler to calculate.

In the cases you're looking at (pfn to map number) giving it pfn << PAGE_SHIFT is entirely sufficient, and is in fact optimal for performance.

Signature · 3 lines
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core
#9 lore raw
Quoted 3 lines · On Mon, 3 Apr 2006 10:02:07 +0100 Russell King <[email protected]>…

In turn, that means that we can pass it whatever address we happen to have available at the time, or whichever is simpler to calculate.

interesting :)

Quoted 3 lines

In the cases you're looking at (pfn to map number) giving it pfn << PAGE_SHIFT is entirely sufficient, and is in fact optimal for performance.

Ok, I'll post fixed patch, which uses LOCAL_MAP_NR((pfn) << PAGE_SHIFT)

Thank you for advices!

--Kame