Skip to contentSkip to conversation

MIPS: fix pfn_valid() for FLAGMEM

PATCH In review Wu Zhangjin 4 participants 12 messages Oct 8, 2009 – Oct 9, 2009 MIPS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 MIPS: fix pfn_valid() for FLAGMEM

When CONFIG_FLAGMEM enabled, STD/Hiberation will fail on YeeLoong laptop, This patch fix it:

if pfn is between min_low_pfn and max_mapnr, the old pfn_valid() will return TRUE, but in reality, if the memory is not continuous, it should be false. for example:

$ cat /proc/iomem | grep "System RAM"
00000000-0fffffff : System RAM
90000000-bfffffff : System RAM

as we can see, it is not continuous, so, some of the memory is not valid but regarded as valid by pfn_valid(), and at last make STD/Hibernate fail when shrinking a too large number of invalid memory.

Here, we fix it via checking pfn is in the "System RAM" or not, if yes, return TRUE.

---
 arch/mips/include/asm/page.h |   11 ++++-------
 arch/mips/mm/page.c          |   17 +++++++++++++++++
 2 files changed, 21 insertions(+), 7 deletions(-)
arch/mips/include/asm/page.h +4 -7
index f266295..16903a6 100644
@@ -168,13 +168,10 @@ typedef struct { unsigned long pgprot; } pgprot_t;
 
 #ifdef CONFIG_FLATMEM
 
-#define pfn_valid(pfn)							\
-({									\
-	unsigned long __pfn = (pfn);					\
-	/* avoid <linux/bootmem.h> include hell */			\
-	extern unsigned long min_low_pfn;				\
-									\
-	__pfn >= min_low_pfn && __pfn < max_mapnr;			\
+#define pfn_valid(pfn)				\
+({						\
+	extern int is_pfn_valid(unsigned long); \
+	is_pfn_valid(pfn);			\
 })
 
 #elif defined(CONFIG_SPARSEMEM)
arch/mips/mm/page.c +17 -0
index f5c7375..48a4d2a 100644
@@ -689,3 +689,20 @@ void copy_page(void *to, void *from)
 }
 
 #endif /* CONFIG_SIBYTE_DMA_PAGEOPS */
+
+#ifdef CONFIG_FLATMEM
+int is_pfn_valid(unsigned long pfn)
+{
+	int i;
+
+	for (i = 0; i < boot_mem_map.nr_map; i++) {
+		if (boot_mem_map.map[i].type == BOOT_MEM_RAM) {
+			if ((pfn >= PFN_DOWN(boot_mem_map.map[i].addr)) &&
+				((pfn) <= (PFN_UP(boot_mem_map.map[i].addr +
+					boot_mem_map.map[i].size))))
+				return 1;
+		}
+	}
+	return 0;
+}
+#endif
Signature · 1 line
1.6.2.1
#1 lore raw
Quoted 11 lines · Wu Zhangjin

When CONFIG_FLAGMEM enabled, STD/Hiberation will fail on YeeLoong laptop, This patch fix it:

if pfn is between min_low_pfn and max_mapnr, the old pfn_valid() will return TRUE, but in reality, if the memory is not continuous, it should be false. for example:

$ cat /proc/iomem | grep "System RAM"
00000000-0fffffff : System RAM
90000000-bfffffff : System RAM
Quoted 6 lines

as we can see, it is not continuous, so, some of the memory is not valid but regarded as valid by pfn_valid(), and at last make STD/Hibernate fail when shrinking a too large number of invalid memory.

Here, we fix it via checking pfn is in the "System RAM" or not, if yes, return TRUE.

"return FALSE"?

Quoted 1 line

Looks mostly ok, small comments below.

Quoted 6 lines
arch/mips/include/asm/page.h +0 -2
@@ -168,13 +168,10 @@ typedef struct { unsigned long pgprot; } pgprot_t;
 
 #ifdef CONFIG_FLATMEM
 
-#define pfn_valid(pfn)							\
-({									\

arch/mips/include/asm/page.h typedef struct { unsigned long pgprot; } pgprot_t; · line 175

Quoted 10 lines
arch/mips/include/asm/page.h +4 -5
-	unsigned long __pfn = (pfn);					\
-	/* avoid <linux/bootmem.h> include hell */			\
-	extern unsigned long min_low_pfn;				\
-									\
-	__pfn >= min_low_pfn && __pfn < max_mapnr;			\
+#define pfn_valid(pfn)				\
+({						\
+	extern int is_pfn_valid(unsigned long); \
+	is_pfn_valid(pfn);			\
 })

"extern int pfn_valid here"

...and get away without the ugly macro?

arch/mips/mm/page.c void copy_page(void *to, void *from) · line 694

Quoted 12 lines
arch/mips/include/asm/page.h +0 -0
 #elif defined(CONFIG_SPARSEMEM)
arch/mips/mm/page.c +3 -0
index f5c7375..48a4d2a 100644
@@ -689,3 +689,20 @@ void copy_page(void *to, void *from)
 }
 
 #endif /* CONFIG_SIBYTE_DMA_PAGEOPS */
+
+#ifdef CONFIG_FLATMEM
+int is_pfn_valid(unsigned long pfn)

...with simple function rename?
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#2 lore raw

Hi,

Quoted 44 lines · Pavel Machek
Quoted 11 lines · Wu Zhangjin

When CONFIG_FLAGMEM enabled, STD/Hiberation will fail on YeeLoong laptop, This patch fix it:

if pfn is between min_low_pfn and max_mapnr, the old pfn_valid() will return TRUE, but in reality, if the memory is not continuous, it should be false. for example:

$ cat /proc/iomem | grep "System RAM"
00000000-0fffffff : System RAM
90000000-bfffffff : System RAM
Quoted 6 lines

as we can see, it is not continuous, so, some of the memory is not valid but regarded as valid by pfn_valid(), and at last make STD/Hibernate fail when shrinking a too large number of invalid memory.

Here, we fix it via checking pfn is in the "System RAM" or not, if yes, return TRUE.

"return FALSE"?

Quoted 1 line

Looks mostly ok, small comments below.

Quoted 6 lines
arch/mips/include/asm/page.h +0 -2
@@ -168,13 +168,10 @@ typedef struct { unsigned long pgprot; } pgprot_t;
 
 #ifdef CONFIG_FLATMEM
 
-#define pfn_valid(pfn)							\
-({									\

arch/mips/include/asm/page.h typedef struct { unsigned long pgprot; } pgprot_t; · line 175

Quoted 10 lines
arch/mips/include/asm/page.h +4 -5
-	unsigned long __pfn = (pfn);					\
-	/* avoid <linux/bootmem.h> include hell */			\
-	extern unsigned long min_low_pfn;				\
-									\
-	__pfn >= min_low_pfn && __pfn < max_mapnr;			\
+#define pfn_valid(pfn)				\
+({						\
+	extern int is_pfn_valid(unsigned long); \
+	is_pfn_valid(pfn);			\
 })

"extern int pfn_valid here"

Quoted 2 lines

...and get away without the ugly macro?

Perhaps need to move the whole "#ifdef CONFIG_FLATMEM" to #ifndef ASSEMBLY, otherwise,

"arch/mips/include/asm/page.h:170: Error: unrecognized opcode `extern int pfn_valid(unsigned long)'".

Regards,
Wu Zhangjin

#3 lore raw
Quoted 47 lines · Wu Zhangjin

Hi,

Quoted 44 lines · Pavel Machek
Quoted 11 lines · Wu Zhangjin

When CONFIG_FLAGMEM enabled, STD/Hiberation will fail on YeeLoong laptop, This patch fix it:

if pfn is between min_low_pfn and max_mapnr, the old pfn_valid() will return TRUE, but in reality, if the memory is not continuous, it should be false. for example:

$ cat /proc/iomem | grep "System RAM"
00000000-0fffffff : System RAM
90000000-bfffffff : System RAM
Quoted 6 lines

as we can see, it is not continuous, so, some of the memory is not valid but regarded as valid by pfn_valid(), and at last make STD/Hibernate fail when shrinking a too large number of invalid memory.

Here, we fix it via checking pfn is in the "System RAM" or not, if yes, return TRUE.

"return FALSE"?

Quoted 1 line

Looks mostly ok, small comments below.

Quoted 6 lines
arch/mips/include/asm/page.h +0 -2
@@ -168,13 +168,10 @@ typedef struct { unsigned long pgprot; } pgprot_t;
 
 #ifdef CONFIG_FLATMEM
 
-#define pfn_valid(pfn)							\
-({									\

arch/mips/include/asm/page.h typedef struct { unsigned long pgprot; } pgprot_t; · line 175

Quoted 10 lines
arch/mips/include/asm/page.h +4 -5
-	unsigned long __pfn = (pfn);					\
-	/* avoid <linux/bootmem.h> include hell */			\
-	extern unsigned long min_low_pfn;				\
-									\
-	__pfn >= min_low_pfn && __pfn < max_mapnr;			\
+#define pfn_valid(pfn)				\
+({						\
+	extern int is_pfn_valid(unsigned long); \
+	is_pfn_valid(pfn);			\
 })

"extern int pfn_valid here"

Quoted 8 lines
Quoted 2 lines

...and get away without the ugly macro?

Perhaps need to move the whole "#ifdef CONFIG_FLATMEM" to #ifndef ASSEMBLY, otherwise,

"arch/mips/include/asm/page.h:170: Error: unrecognized opcode `extern int pfn_valid(unsigned long)'".

I guess so. pfn_valid() will not work from assembly, anywa, so...
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#4 lore raw

Hello,

Quoted 25 lines
Quoted 25 lines
Quoted 24 lines

Looks mostly ok, small comments below.

Quoted 6 lines
arch/mips/include/asm/page.h +0 -2
@@ -168,13 +168,10 @@ typedef struct { unsigned long pgprot; } pgprot_t;
 
 #ifdef CONFIG_FLATMEM
 
-#define pfn_valid(pfn)							\
-({									\

arch/mips/include/asm/page.h typedef struct { unsigned long pgprot; } pgprot_t; · line 175

Quoted 10 lines
arch/mips/include/asm/page.h +4 -5
-	unsigned long __pfn = (pfn);					\
-	/* avoid <linux/bootmem.h> include hell */			\
-	extern unsigned long min_low_pfn;				\
-									\
-	__pfn >= min_low_pfn && __pfn < max_mapnr;			\
+#define pfn_valid(pfn)				\
+({						\
+	extern int is_pfn_valid(unsigned long); \
+	is_pfn_valid(pfn);			\
 })

"extern int pfn_valid here"

...and get away without the ugly macro?

Quoted 7 lines
Quoted 5 lines

Perhaps need to move the whole "#ifdef CONFIG_FLATMEM" to #ifndef ASSEMBLY, otherwise,

"arch/mips/include/asm/page.h:170: Error: unrecognized opcode `extern int pfn_valid(unsigned long)'".

I guess so. pfn_valid() will not work from assembly, anywa, so...

Seems pfn_valid() is only called in non-ASSEMBLY source code, so, we are safe to move it to "#ifndef ASSEMBLY", just tested it, works.

Regards,
Wu Zhangjin

#5 lore raw
In reply to Wu Zhangjin

Hello.

Quoted 2 lines · Wu Zhangjin

When CONFIG_FLAGMEM enabled, STD/Hiberation will fail on YeeLoong

You surely meant FLATMEM here and the subject.

Quoted 2 lines

laptop, This patch fix it:

Fixes.

Quoted 2 lines

[...]

Quoted 10 lines
arch/mips/include/asm/page.h +0 -2
index f266295..16903a6 100644
@@ -168,13 +168,10 @@ typedef struct { unsigned long pgprot; } pgprot_t;
 
 #ifdef CONFIG_FLATMEM
 
-#define pfn_valid(pfn)							\
-({									\

arch/mips/include/asm/page.h typedef struct { unsigned long pgprot; } pgprot_t; · line 175

Quoted 10 lines
arch/mips/include/asm/page.h +4 -5
-	unsigned long __pfn = (pfn);					\
-	/* avoid <linux/bootmem.h> include hell */			\
-	extern unsigned long min_low_pfn;				\
-									\
-	__pfn >= min_low_pfn && __pfn < max_mapnr;			\
+#define pfn_valid(pfn)				\
+({						\
+	extern int is_pfn_valid(unsigned long); \
+	is_pfn_valid(pfn);			\
 

Why not just define pfn_valid() as *extern* function in this case?

Quoted 9 lines
arch/mips/mm/page.c +0 -0
index f5c7375..48a4d2a 100644
@@ -689,3 +689,20 @@ void copy_page(void *to, void *from)
 }
 
 #endif /* CONFIG_SIBYTE_DMA_PAGEOPS */

arch/mips/mm/page.c void copy_page(void *to, void *from) · line 701

Quoted 10 lines
arch/mips/mm/page.c +10 -0
+
+#ifdef CONFIG_FLATMEM
+int is_pfn_valid(unsigned long pfn)
+{
+	int i;
+
+	for (i = 0; i < boot_mem_map.nr_map; i++) {
+		if (boot_mem_map.map[i].type == BOOT_MEM_RAM) {
+			if ((pfn >= PFN_DOWN(boot_mem_map.map[i].addr)) &&
+				((pfn) <= (PFN_UP(boot_mem_map.map[i].addr +

Not <?

arch/mips/mm/page.c void copy_page(void *to, void *from) · line 708

Quoted 8 lines
arch/mips/mm/page.c +7 -0
+					boot_mem_map.map[i].size))))
+				return 1;
+		}
+	}
+	return 0;
+}
+#endif

WBR, Sergei

#6 lore raw

Hello,

Quoted 10 lines
Quoted 2 lines

When CONFIG_FLAGMEM enabled, STD/Hiberation will fail on YeeLoong

You surely meant FLATMEM here and the subject.

Quoted 2 lines

laptop, This patch fix it:

Fixes.

Thanks, will resend a new one later.

Quoted 33 lines
Quoted 2 lines

[...]

Quoted 10 lines
arch/mips/include/asm/page.h +0 -2
index f266295..16903a6 100644
@@ -168,13 +168,10 @@ typedef struct { unsigned long pgprot; } pgprot_t;
 
 #ifdef CONFIG_FLATMEM
 
-#define pfn_valid(pfn)							\
-({									\

arch/mips/include/asm/page.h typedef struct { unsigned long pgprot; } pgprot_t; · line 175

Quoted 10 lines
arch/mips/include/asm/page.h +4 -5
-	unsigned long __pfn = (pfn);					\
-	/* avoid <linux/bootmem.h> include hell */			\
-	extern unsigned long min_low_pfn;				\
-									\
-	__pfn >= min_low_pfn && __pfn < max_mapnr;			\
+#define pfn_valid(pfn)				\
+({						\
+	extern int is_pfn_valid(unsigned long); \
+	is_pfn_valid(pfn);			\
 

Why not just define pfn_valid() as *extern* function in this case?

Quoted 7 lines
arch/mips/mm/page.c +0 -0
index f5c7375..48a4d2a 100644
@@ -689,3 +689,20 @@ void copy_page(void *to, void *from)
 }
 
Quoted 15 lines

arch/mips/mm/page.c void copy_page(void *to, void *from) · line 701

Quoted 12 lines
arch/mips/mm/page.c +10 -0
 #endif /* CONFIG_SIBYTE_DMA_PAGEOPS */
+
+#ifdef CONFIG_FLATMEM
+int is_pfn_valid(unsigned long pfn)
+{
+	int i;
+
+	for (i = 0; i < boot_mem_map.nr_map; i++) {
+		if (boot_mem_map.map[i].type == BOOT_MEM_RAM) {
+			if ((pfn >= PFN_DOWN(boot_mem_map.map[i].addr)) &&
+				((pfn) <= (PFN_UP(boot_mem_map.map[i].addr +
   Not <?

Just checked it again, here should be <.

Regards,
Wu Zhangjin

#7 lore raw
In reply to Wu Zhangjin
Quoted 6 lines · Wu Zhangjin

When CONFIG_FLAGMEM enabled, STD/Hiberation will fail on YeeLoong laptop, This patch fix it:

if pfn is between min_low_pfn and max_mapnr, the old pfn_valid() will return TRUE, but in reality, if the memory is not continuous, it should be false. for example:

Hm... All that pfn_valid() indicates is that a page frame number is valid to index a pfn. That is that a pfn is valid to index the mem_map array.

Quoted 10 lines
$ cat /proc/iomem | grep "System RAM"
00000000-0fffffff : System RAM
90000000-bfffffff : System RAM

as we can see, it is not continuous, so, some of the memory is not valid but regarded as valid by pfn_valid(), and at last make STD/Hibernate fail when shrinking a too large number of invalid memory.

Here, we fix it via checking pfn is in the "System RAM" or not, if yes, return TRUE.

Are the non-memory parts marked as reserved?

Ralf

#8 lore raw
Quoted 16 lines · Ralf Baechle
Quoted 6 lines · Wu Zhangjin

When CONFIG_FLAGMEM enabled, STD/Hiberation will fail on YeeLoong laptop, This patch fix it:

if pfn is between min_low_pfn and max_mapnr, the old pfn_valid() will return TRUE, but in reality, if the memory is not continuous, it should be false. for example:

Hm... All that pfn_valid() indicates is that a page frame number is valid to index a pfn. That is that a pfn is valid to index the mem_map array.

Quoted 4 lines
$ cat /proc/iomem | grep "System RAM"
00000000-0fffffff : System RAM
90000000-bfffffff : System RAM
Quoted 9 lines
Quoted 6 lines

as we can see, it is not continuous, so, some of the memory is not valid but regarded as valid by pfn_valid(), and at last make STD/Hibernate fail when shrinking a too large number of invalid memory.

Here, we fix it via checking pfn is in the "System RAM" or not, if yes, return TRUE.

Are the non-memory parts marked as reserved?

No, so, is that a need to mark them?

Regrads,
Wu Zhangjin

#9 lore raw
Quoted 3 lines · Wu Zhangjin
Quoted 2 lines

Are the non-memory parts marked as reserved?

No, so, is that a need to mark them?

Initially all pages are marked as reserved.

Which seems to be good enough for x86:

$ cat /proc/iomem
00000000-0009efff : System RAM
0009f000-0009ffff : reserved
000c0000-000cffff : pnp 00:0d
000e0000-000fffff : pnp 00:0d
00100000-7fe5b7ff : System RAM
[...]

The 0x9f000 - 0x9ffff range is the good old ISA I/O memory range (classic MDA/CGA/VGA etc.), that is non-memory yet:

#ifdef CONFIG_FLATMEM
#define pfn_valid(pfn) ((pfn) < max_mapnr)
#endif /* CONFIG_FLATMEM */

is sufficient on x86 so I think something else must be wrong.

Ralf

#10 lore raw

Hello.

Quoted 16 lines · Ralf Baechle
Quoted 3 lines
Quoted 1 line

Are the non-memory parts marked as reserved?

No, so, is that a need to mark them?

Initially all pages are marked as reserved.

Which seems to be good enough for x86:

$ cat /proc/iomem
00000000-0009efff : System RAM
0009f000-0009ffff : reserved
000c0000-000cffff : pnp 00:0d
000e0000-000fffff : pnp 00:0d
00100000-7fe5b7ff : System RAM
[...]
Quoted 2 lines

The 0x9f000 - 0x9ffff range is the good old ISA I/O memory range (classic MDA/CGA/VGA etc.), that is non-memory yet:

Not really, it's a usual RAM. CGA/VGA video memory occupies
000a0000-000bffff and MDA occupies 000b0000-000b7ffff (if not less). This range is probably reserved by BIOS for something like EBDA...

WBR, Sergei

#11 lore raw
Quoted 16 lines · Hello, I wrote:
Quoted 15 lines
Quoted 3 lines
Quoted 1 line

Are the non-memory parts marked as reserved?

No, so, is that a need to mark them?

Initially all pages are marked as reserved.

Which seems to be good enough for x86:

$ cat /proc/iomem
00000000-0009efff : System RAM
0009f000-0009ffff : reserved
000c0000-000cffff : pnp 00:0d
000e0000-000fffff : pnp 00:0d
00100000-7fe5b7ff : System RAM
[...]
Quoted 5 lines
Quoted 2 lines

The 0x9f000 - 0x9ffff range is the good old ISA I/O memory range (classic MDA/CGA/VGA etc.), that is non-memory yet:

Not really, it's a usual RAM. CGA/VGA video memory occupies

Oh, I meant EGA/VGA. CGA memory is at 000b8000-000bffff, of course.

Quoted 2 lines

000a0000-000bffff and MDA occupies 000b0000-000b7ffff (if not less). This range is probably reserved by BIOS for something like EBDA...

Which stands for Extended BIOS Data Area.

WBR, Sergei