Get ride of CPHYSADDR() in setup.c [take #2]
cover Get ride of CPHYSADDR() in setup.c [take #2]
Here's the take #2.
I changed the definition of __pa() for 64-bits kernels to match the one suggested by Atsushi. It should be safer.
It also makes virt_to_page() uses virt_to_phys() instead of __pa().
Unfortunately, no tests have been done for 64 bit kernels because of lacks of hardware. If anybody could give a try that would be great.
Please consider,
Franck
---
arch/mips/kernel/setup.c | 55 +++++++++++++++++++++++++------------------- arch/mips/mm/init.c | 42 +++++++++++++++------------------- include/asm-mips/io.h | 2 +- include/asm-mips/page.h | 14 ++++++++--- include/asm-mips/pgtable.h | 2 +- 5 files changed, 62 insertions(+), 53 deletions(-)
PATCH 1/7 page.h: remove __pa() usages.
__pa() was used by virt_to_page() and virt_addr_valid(). These latter are used when kernel is initialised so __pa() is not appropriate, we use virt_to_phys() instead.
Futhermore __pa() is going to take care of CKSEG0/XKPHYS address mix for 64 bit kernels. This makes __pa() more complex than virt_to_phys() and this extra work is not needed by virt_to_page() and virt_addr_valid().
Eventually it consolidates virt_to_phys() prototype by making its argument 'const'. this avoids some warnings that was due to some virt_to_page() usages which pass const pointer.
--- arch/mips/mm/init.c | 8 ++++---- include/asm-mips/io.h | 2 +- include/asm-mips/page.h | 4 ++-- include/asm-mips/pgtable.h | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-)
arch/mips/mm/init.c +4 -4
@@ -90,9 +90,9 @@ unsigned long setup_zero_pages(void)if (!empty_zero_page)panic ("Oh boy, that early out of memory?" ); - page =virt_to_page (empty_zero_page); + page =virt_to_page ((void *)empty_zero_page);split_page (page, order); -while (page <virt_to_page (empty_zero_page + (PAGE_SIZE << order))) { +while (page <virt_to_page ((void *)(empty_zero_page + (PAGE_SIZE << order)))) {SetPageReserved (page); page++; }
@@ -490,8 +490,8 @@ void free_init_pages(char *what, unsigneunsigned long addr;for (addr = begin; addr < end; addr +=PAGE_SIZE ) { -ClearPageReserved (virt_to_page (addr)); -init_page_count (virt_to_page (addr)); +ClearPageReserved (virt_to_page ((void *)addr)); +init_page_count (virt_to_page ((void *)addr));memset ((void *)addr,0xcc ,PAGE_SIZE );free_page (addr); totalram_pages++;
include/asm-mips/io.h +1 -1
@@ -113,7 +113,7 @@ #endif* almost all conceivable cases a device driver should not be using * this function */ -static inline unsigned long virt_to_phys (volatile void * address) +static inline unsigned long virt_to_phys (volatile const void *address) {return (unsigned long )address -PAGE_OFFSET ; }
include/asm-mips/page.h +2 -2
@@ -157,8 +157,8 @@ ({ \#endif -#define virt_to_page (kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT) -#define virt_addr_valid (kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT) +#define virt_to_page (kaddr) pfn_to_page(PFN_DOWN(virt_to_phys(kaddr))) +#define virt_addr_valid (kaddr) pfn_valid(PFN_DOWN(virt_to_phys(kaddr)))#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \ VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
include/asm-mips/pgtable.h +1 -1
@@ -67,7 +67,7 @@ extern unsigned long empty_zero_page;extern unsigned long zero_page_mask;#define ZERO_PAGE (vaddr) \ - (virt_to_page(empty_zero_page + (((unsigned long)(vaddr)) & zero_page_mask))) + (virt_to_page((void *)(empty_zero_page + (((unsigned long)(vaddr)) & zero_page_mask))))#define __HAVE_ARCH_MOVE_PTE#define move_pte (pte, prot, old_addr, new_addr) \
Signature · 1 line
1.4.2.3
Re: [PATCH 1/7] page.h: remove __pa() usages.
include/asm-mips/page.h ({ \ · line 161
Quoted 4 lines · Franck Bui-Huu
include/asm-mips/page.h +2
-2-#define virt_to_page (kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT) -#define virt_addr_valid (kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT) +#define virt_to_page (kaddr) pfn_to_page(PFN_DOWN(virt_to_phys(kaddr))) +#define virt_addr_valid (kaddr) pfn_valid(PFN_DOWN(virt_to_phys(kaddr)))
It seems "#include <linux/pfn.h>" (and "#include <asm/io.h>" perhaps) required.
---
Atsushi Nemoto
Re: [PATCH 1/7] page.h: remove __pa() usages.
Quoted 9 lines · Atsushi Nemoto
include/asm-mips/page.h ({ \ · line 161
Quoted 4 lines · Franck Bui-Huu
include/asm-mips/page.h +2
-2-#define virt_to_page (kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT) -#define virt_addr_valid (kaddr) pfn_valid(__pa(kaddr) >> PAGE_SHIFT) +#define virt_to_page (kaddr) pfn_to_page(PFN_DOWN(virt_to_phys(kaddr))) +#define virt_addr_valid (kaddr) pfn_valid(PFN_DOWN(virt_to_phys(kaddr)))It seems "#include <
linux/pfn.h>" (and "#include <asm/io.h>" perhaps) required.
Well it just compiles fine for me and to be honest I have no strong feeling here. So I'm following your recommendation.
thanks
Signature · 1 line
Franck
PATCH 2/7 Make __pa() aware of XKPHYS/CKSEG0 address mix for 64 bit kernels
In reply to Franck Bui-HuuDuring early boot mem init, some configs couldn't use __pa() to convert virtual into physical addresses. Specially for 64 bit kernel cases when CONFIG_BUILD_ELF64=n. This patch make __pa() work for _all_ configs and thus make CPHYSADDR() useless.
--- include/asm-mips/page.h | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-)
include/asm-mips/page.h +7 -2
@@ -131,8 +131,13 @@ #endif /* !__ASSEMBLY__ *//* to align the pointer to the (next) page boundary */ #define PAGE_ALIGN (addr) (((addr) + PAGE_SIZE - 1) & PAGE_MASK) -#define __pa (x) ((unsigned long) (x) - PAGE_OFFSET) -#define __va (x) ((void *)((unsigned long) (x) + PAGE_OFFSET)) +#if defined(CONFIG_64BITS ) && !defined(CONFIG_BUILD_ELF64 ) +#define __page_offset (x) ((unsigned long)(x) < CKSEG0 ? PAGE_OFFSET : CKSEG0) +#else +#define __page_offset (x) PAGE_OFFSET +#endif +#define __pa (x) ((unsigned long)(x) - __page_offset(x)) +#define __va (x) ((void *)((unsigned long)(x) + __page_offset(x)))#define pfn_to_kaddr (pfn) __va((pfn) << PAGE_SHIFT)
Signature · 1 line
1.4.2.3
Re: [PATCH 2/7] Make __pa() aware of XKPHYS/CKSEG0 address mix for 64 bit kernels
include/asm-mips/page.h #endif /* !__ASSEMBLY__ */ · line 140
Quoted 9 lines · Franck Bui-Huu
include/asm-mips/page.h +7
-2-#define __pa (x) ((unsigned long) (x) - PAGE_OFFSET) -#define __va (x) ((void *)((unsigned long) (x) + PAGE_OFFSET)) +#if defined(CONFIG_64BITS ) && !defined(CONFIG_BUILD_ELF64 ) +#define __page_offset (x) ((unsigned long)(x) < CKSEG0 ? PAGE_OFFSET : CKSEG0) +#else +#define __page_offset (x) PAGE_OFFSET +#endif +#define __pa (x) ((unsigned long)(x) - __page_offset(x)) +#define __va (x) ((void *)((unsigned long)(x) + __page_offset(x)))
In __va(), you are passing an physical address to __page_offset().
---
Atsushi Nemoto
Re: [PATCH 2/7] Make __pa() aware of XKPHYS/CKSEG0 address mix for 64 bit kernels
Quoted 13 lines · Atsushi Nemoto
include/asm-mips/page.h #endif /* !__ASSEMBLY__ */ · line 140
Quoted 9 lines · Franck Bui-Huu
include/asm-mips/page.h +7
-2-#define __pa (x) ((unsigned long) (x) - PAGE_OFFSET) -#define __va (x) ((void *)((unsigned long) (x) + PAGE_OFFSET)) +#if defined(CONFIG_64BITS ) && !defined(CONFIG_BUILD_ELF64 ) +#define __page_offset (x) ((unsigned long)(x) < CKSEG0 ? PAGE_OFFSET : CKSEG0) +#else +#define __page_offset (x) PAGE_OFFSET +#endif +#define __pa (x) ((unsigned long)(x) - __page_offset(x)) +#define __va (x) ((void *)((unsigned long)(x) + __page_offset(x)))In
__va(), you are passing an physical address to__page_offset().
oops, good catch ! I'll change that.
thanks
Signature · 1 line
Franck
Re: [PATCH 2/7] Make __pa() aware of XKPHYS/CKSEG0 address mix for 64 bit kernels
In reply to Franck Bui-HuuReview
Quoted 2 lines · Franck Bui-Huu
(quoted diff) +2
-0+#if defined(CONFIG_64BITS) && !defined(CONFIG_BUILD_ELF64) +#define __page_offset(x) ((unsigned long)(x) < CKSEG0 ? PAGE_OFFSET : CKSEG0)
CONFIG_64BIT, not CONFIG_64BITS. Sorry, my mistake.
Also since CKSEG0 is defined with _LLCONST_ macro, the final type of __page_offset(), __pa(), __pa_sym() will be "unsigned long long", not "unsigned long". This raise a "comparison of distinct pointer types lacks a cast" warning on this line.
reserved_end = max(init_initrd(), PFN_UP(__pa_symbol(&_end)));
A qiuck and non-intrusive hack would be cast CKSEG0 with "unsigned long" here, but it might be preferred to change _LLCONST_ definition like this. What do you think?
Subject: Use "long" for _ATYPE64_ and _LLCONST_ on 64-bit kernel.
include/asm-mips/addrspace.h +5 -0
@@ -23,9 +23,14 @@ #define _LLCONST_(x) x#else #define _ATYPE_ __PTRDIFF_TYPE__#define _ATYPE32_ int +#ifdef CONFIG_64BIT +#define _ATYPE64_ long +#define _LLCONST_ (x) x ## L +#else #define _ATYPE64_ long long#define _LLCONST_ (x) x ## LL#endif +#endif /* * 32-bit MIPS address spaces
---
Atsushi Nemoto
Re: [PATCH 2/7] Make __pa() aware of XKPHYS/CKSEG0 address mix for 64 bit kernels
Quoted 5 lines · Atsushi Nemoto
A qiuck and non-intrusive hack would be cast CKSEG0 with "unsigned long" here, but it might be preferred to change _LLCONST_ definition like this. What do you think?
I think _LLCONST_ change is the correct thing to do. Can you please submit your patch to Ralf ?
thanks
Signature · 1 line
Franck
Re: [PATCH 2/7] Make __pa() aware of XKPHYS/CKSEG0 address mix for 64 bit kernels
In reply to Atsushi NemotoQuoted 27 lines · On Thu, 19 Oct 2006 13:01:33 +0900 (JST) Atsushi Nemoto <[email protected]>…
Review
Quoted 2 lines · Franck Bui-Huu
(quoted diff) +2
-0+#if defined(CONFIG_64BITS) && !defined(CONFIG_BUILD_ELF64) +#define __page_offset(x) ((unsigned long)(x) < CKSEG0 ? PAGE_OFFSET : CKSEG0)
CONFIG_64BIT, notCONFIG_64BITS. Sorry, my mistake.Also since CKSEG0 is defined with _LLCONST_ macro, the final type of
__page_offset(),__pa(),__pa_sym()will be "unsigned long long", not "unsigned long". This raise a "comparison of distinct pointer types lacks a cast" warning on this line.reserved_end = max(init_initrd(), PFN_UP(__pa_symbol(&_end)));A qiuck and non-intrusive hack would be cast CKSEG0 with "unsigned long" here, but it might be preferred to change _LLCONST_ definition like this. What do you think?
Subject: Use "long" for _ATYPE64_ and _LLCONST_ on 64-bit kernel.
Signed-off-by Atsushi Nemoto <[email protected]>include/asm-mips/addrspace.h +0
-0
include/asm-mips/addrspace.h #define _LLCONST_(x) x · line 28
Quoted 6 lines
include/asm-mips/addrspace.h +3
-0@@ -23,9 +23,14 @@ #define _LLCONST_(x) x#else #define _ATYPE_ __PTRDIFF_TYPE__#define _ATYPE32_ int +#ifdef CONFIG_64BIT +#define _ATYPE64_ long +#define _LLCONST_ (x) x ## L
^^ ^
The name is not corresponding to reality.
It's not so good.
Yoichi
Re: [PATCH 2/7] Make __pa() aware of XKPHYS/CKSEG0 address mix for 64 bit kernels
Quoted 4 lines · Yoichi Yuasa
Quoted 1 line
+#define
_LLCONST_(x)x ## L^^ ^
The name is not corresponding to reality.
It's not so good.
Indeed. How about this?
Subject: Use "long" for 64-bit values on 64-bit kernel.
include/asm-mips/addrspace.h +22 -17
@@ -19,12 +19,17 @@ #ifdef __ASSEMBLY__#define _ATYPE_#define _ATYPE32_#define _ATYPE64_ -#define _LLCONST_ (x) x +#define _CONST64_ (x) x#else #define _ATYPE_ __PTRDIFF_TYPE__#define _ATYPE32_ int +#ifdef CONFIG_64BIT +#define _ATYPE64_ long +#define _CONST64_ (x) x ## L +#else #define _ATYPE64_ long long -#define _LLCONST_ (x) x ## LL +#define _CONST64_ (x) x ## LL +#endif #endif /*
@@ -48,7 +53,7 @@ #define KSEGX(a) ((_ACAST32_ (a)) & 0xe*/ #define CPHYSADDR (a) ((_ACAST32_(a)) & 0x1fffffff)#define XPHYSADDR (a) ((_ACAST64_(a)) & \ - _LLCONST_(0x000000ffffffffff)) + _CONST64_(0x000000ffffffffff))#ifdef CONFIG_64BIT
@@ -57,14 +62,14 @@ #ifdef CONFIG_64BIT* The compatibility segments use the full 64-bit sign extended value. Note * the R8000 doesn't have them so don't reference these in generic MIPS code. */ -#define XKUSEG _LLCONST_(0x0000000000000000) -#define XKSSEG _LLCONST_(0x4000000000000000) -#define XKPHYS _LLCONST_(0x8000000000000000) -#define XKSEG _LLCONST_(0xc000000000000000) -#define CKSEG0 _LLCONST_(0xffffffff80000000) -#define CKSEG1 _LLCONST_(0xffffffffa0000000) -#define CKSSEG _LLCONST_(0xffffffffc0000000) -#define CKSEG3 _LLCONST_(0xffffffffe0000000) +#define XKUSEG _CONST64_(0x0000000000000000) +#define XKSSEG _CONST64_(0x4000000000000000) +#define XKPHYS _CONST64_(0x8000000000000000) +#define XKSEG _CONST64_(0xc000000000000000) +#define CKSEG0 _CONST64_(0xffffffff80000000) +#define CKSEG1 _CONST64_(0xffffffffa0000000) +#define CKSSEG _CONST64_(0xffffffffc0000000) +#define CKSEG3 _CONST64_(0xffffffffe0000000)#define CKSEG0ADDR (a) (CPHYSADDR(a) | CKSEG0)#define CKSEG1ADDR (a) (CPHYSADDR(a) | CKSEG1)
@@ -122,7 +127,7 @@ #define K_CALG_UNCACHED_ACCEL 7#define PHYS_TO_XKSEG_UNCACHED (p) PHYS_TO_XKPHYS(K_CALG_UNCACHED,(p))#define PHYS_TO_XKSEG_CACHED (p) PHYS_TO_XKPHYS(K_CALG_COH_SHAREABLE,(p))#define XKPHYS_TO_PHYS (p) ((p) & TO_PHYS_MASK) -#define PHYS_TO_XKPHYS (cm,a) (_LLCONST_(0x8000000000000000) | \ +#define PHYS_TO_XKPHYS (cm,a) (_CONST64_(0x8000000000000000) | \ ((cm)<<59) | (a))#if defined (CONFIG_CPU_R4300 ) \
@@ -132,20 +137,20 @@ #if defined (CONFIG_CPU_R4300) \ || defined (CONFIG_CPU_NEVADA ) \ || defined (CONFIG_CPU_TX49XX ) \ || defined (CONFIG_CPU_MIPS64 ) -#define TO_PHYS_MASK _LLCONST_(0x0000000fffffffff)/* 2^^36 - 1 */ +#define TO_PHYS_MASK _CONST64_(0x0000000fffffffff)/* 2^^36 - 1 */ #endif #if defined (CONFIG_CPU_R8000 )/* We keep KUSIZE consistent with R4000 for now (2^^40) instead of (2^^48) */ -#define TO_PHYS_MASK _LLCONST_(0x000000ffffffffff)/* 2^^40 - 1 */ +#define TO_PHYS_MASK _CONST64_(0x000000ffffffffff)/* 2^^40 - 1 */ #endif #if defined (CONFIG_CPU_R10000 ) -#define TO_PHYS_MASK _LLCONST_(0x000000ffffffffff)/* 2^^40 - 1 */ +#define TO_PHYS_MASK _CONST64_(0x000000ffffffffff)/* 2^^40 - 1 */ #endif #if defined(CONFIG_CPU_SB1 ) || defined(CONFIG_CPU_SB1A ) -#define TO_PHYS_MASK _LLCONST_(0x00000fffffffffff)/* 2^^44 - 1 */ +#define TO_PHYS_MASK _CONST64_(0x00000fffffffffff)/* 2^^44 - 1 */ #endif #ifndef CONFIG_CPU_R8000
@@ -155,7 +160,7 @@ #ifndef CONFIG_CPU_R8000* in order to catch bugs in the source code. */ -#define COMPAT_K1BASE32 _LLCONST_(0xffffffffa0000000) +#define COMPAT_K1BASE32 _CONST64_(0xffffffffa0000000)#define PHYS_TO_COMPATK1 (x) ((x) | COMPAT_K1BASE32)/* 32-bit compat k1 */ #endif
Re: [PATCH 2/7] Make __pa() aware of XKPHYS/CKSEG0 address mix for 64 bit kernels
Quoted 25 lines · On Thu, 19 Oct 2006 16:01:45 +0900 (JST) Atsushi Nemoto <[email protected]>…
Quoted 4 lines · Yoichi Yuasa
Quoted 1 line
+#define
_LLCONST_(x)x ## L^^ ^
The name is not corresponding to reality.
It's not so good.Indeed. How about this?
Subject: Use "long" for 64-bit values on 64-bit kernel.
Signed-off-by Atsushi Nemoto <[email protected]>include/asm-mips/addrspace.h +1
-1@@ -19,12 +19,17 @@ #ifdef __ASSEMBLY__#define _ATYPE_#define _ATYPE32_#define _ATYPE64_ -#define _LLCONST_ (x) x +#define _CONST64_ (x) x#else #define _ATYPE_ __PTRDIFF_TYPE__
include/asm-mips/addrspace.h #ifdef __ASSEMBLY__ · line 33
Quoted 10 lines
include/asm-mips/addrspace.h +6
-1#define _ATYPE32_ int +#ifdef CONFIG_64BIT +#define _ATYPE64_ long +#define _CONST64_ (x) x ## L +#else #define _ATYPE64_ long long -#define _LLCONST_ (x) x ## LL +#define _CONST64_ (x) x ## LL +#endif #endif
<snip>
It's good for me.
Thanks,
Yoichi
Re: [PATCH 2/7] Make __pa() aware of XKPHYS/CKSEG0 address mix for 64 bit kernels
In reply to Atsushi NemotoQuoted 8 lines · Atsushi Nemoto
Quoted 4 lines · Yoichi Yuasa
Quoted 1 line
+#define
_LLCONST_(x)x ## L^^ ^
The name is not corresponding to reality.
It's not so good.Indeed. How about this?
or why not simply replacing _LLCONST_ usages by _LCONST_ ? After all, 64 bits value seems to be used only for 64 bits kernels.
Franck
Re: [PATCH 2/7] Make __pa() aware of XKPHYS/CKSEG0 address mix for 64 bit kernels
Quoted 2 lines · Franck Bui-Huu
or why not simply replacing _LLCONST_ usages by _LCONST_ ? After all, 64 bits value seems to be used only for 64 bits kernels.
Well, I suppose 32bit kernel might want to use 64bit values, for example, CONFIG_64BIT_PHYS_ADDR.
---
Atsushi Nemoto
PATCH 3/7 setup.c: get ride of CPHYSADDR()
In reply to Franck Bui-Huuand use new __pa() implementation instead introduced by the previous patch. Indeed this macro can be used now even by the 64 bit kernels with CONFIG_BUILD_ELF64=n config.
--- arch/mips/kernel/setup.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
arch/mips/kernel/setup.c +3 -3
@@ -204,12 +204,12 @@ static void __init finalize_initrd(void)printk (KERN_INFO "Initrd not found or empty" ); goto disable; } -if (CPHYSADDR (initrd_end) >PFN_PHYS (max_low_pfn)) { +if (__pa (initrd_end) >PFN_PHYS (max_low_pfn)) {printk ("Initrd extends beyond end of memory" ); goto disable; } -reserve_bootmem (CPHYSADDR (initrd_start), size); +reserve_bootmem (__pa (initrd_start), size); initrd_below_start_ok =1 ; printk(KERN_INFO "Initial ramdisk at: 0x%lx (%lu bytes)\n",
@@ -256,7 +256,7 @@ static void __init bootmem_init(void)* of usable memory. */ reserved_end =init_initrd (); - reserved_end =PFN_UP (CPHYSADDR (max (reserved_end, (unsigned long )&_end))); + reserved_end =PFN_UP (__pa (max (reserved_end, (unsigned long )&_end)));/* * Find the highest page frame number we have available.
Signature · 1 line
1.4.2.3
PATCH 4/7 Introduce __pa_symbol()
In reply to Franck Bui-HuuThis patch introduces __pa_symbol() macro which should be used to calculate the physical address of kernel symbols. It also relies on RELOC_HIDE() to avoid any compiler's oddities when doing arithmetics on symbols.
--- include/asm-mips/page.h | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
include/asm-mips/page.h +1 -0
@@ -137,6 +137,7 @@ #else#define __page_offset (x) PAGE_OFFSET#endif #define __pa (x) ((unsigned long)(x) - __page_offset(x)) +#define __pa_symbol (x) __pa(RELOC_HIDE((unsigned long)(x),0))#define __va (x) ((void *)((unsigned long)(x) + __page_offset(x)))#define pfn_to_kaddr (pfn) __va((pfn) << PAGE_SHIFT)
Signature · 1 line
1.4.2.3
PATCH 5/7 setup.c: use __pa_symbol() where needed
In reply to Franck Bui-HuuIt should fix the broken code in resource_init() too.
--- arch/mips/kernel/setup.c | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)
arch/mips/kernel/setup.c +5 -5
@@ -256,7 +256,7 @@ static void __init bootmem_init(void)* of usable memory. */ reserved_end =init_initrd (); - reserved_end =PFN_UP (__pa (max (reserved_end, (unsigned long )&_end))); + reserved_end =PFN_UP (max (__pa (reserved_end),__pa_symbol (&_end)));/* * Find the highest page frame number we have available.
@@ -428,10 +428,10 @@ static void __init resource_init(void)if (UNCAC_BASE !=IO_BASE )return ; - code_resource.start =virt_to_phys (&_text); - code_resource.end =virt_to_phys (&_etext) -1 ; - data_resource.start =virt_to_phys (&_etext); - data_resource.end =virt_to_phys (&_edata) -1 ; + code_resource.start =__pa_symbol (&_text); + code_resource.end =__pa_symbol (&_etext) -1 ; + data_resource.start =__pa_symbol (&_etext); + data_resource.end =__pa_symbol (&_edata) -1 ;/* * Request address space for all standard RAM.
Signature · 1 line
1.4.2.3
PATCH 6/7 setup.c: clean up initrd related code
In reply to Franck Bui-Huu--- arch/mips/kernel/setup.c | 43 +++++++++++++++++++++++++------------------ arch/mips/mm/init.c | 5 ----- 2 files changed, 25 insertions(+), 23 deletions(-)
arch/mips/kernel/setup.c +25 -18
@@ -144,14 +144,12 @@ static int __init rd_start_early(char *p {unsigned long start =memparse (p, &p); -#ifdef CONFIG_64BIT -/* HACK: Guess if the sign extension was forgotten */ -if (start >0x0000000080000000 && start <0x00000000ffffffff ) - start |=0xffffffff00000000UL ; -#endif +/* +* No sanity checkings are needed here, they're going to be +* done by init_initrd() soon. +*/ initrd_start = start; initrd_end += start; -return 0 ; }early_param ("rd_start" , rd_start_early);
@@ -159,14 +157,14 @@ early_param("rd_start", rd_start_early);static int __init rd_size_early (char *p) { initrd_end +=memparse (p, &p); -return 0 ; }early_param ("rd_size" , rd_size_early); +/* it returns the next free pfn after initrd */ static unsigned long __init init_initrd (void ) { -unsigned long tmp, end, size; +unsigned long tmp, end;u32 *initrd_header;ROOT_DEV = Root_RAM0;
@@ -176,24 +174,34 @@ static unsigned long __init init_initrd(* already set up initrd_start and initrd_end. In these cases * perfom sanity checks and use them if all looks good. */ - size = initrd_end - initrd_start; -if (initrd_end ==0 || size ==0 ) { - initrd_start =0 ; - initrd_end =0 ; - }else -return initrd_end; +if (initrd_end > initrd_start) + goto sanitize; end = (unsigned long )&_end; tmp =PAGE_ALIGN (end) -sizeof (u32) *2 ;if (tmp < end) tmp +=PAGE_SIZE ; + initrd_start =0 ; + initrd_end =0 ; + end =0 ; initrd_header = (u32 *)tmp;if (initrd_header[0 ] ==0x494E5244 ) { initrd_start = (unsigned long )&initrd_header[2 ]; initrd_end = initrd_start + initrd_header[1 ]; +sanitize: +/* +* Sanitize initrd addresses. For example firmware +* can't guess if they need to pass them through +* 64-bits values if the kernel has been built in pure +* 32-bit. We need also to switch from KSEG0 to XKPHYS +* addresses now, so the code can now safely use __pa(). +*/ + end =__pa (initrd_end); + initrd_end = (unsigned long )__va (end); + initrd_start = (unsigned long )__va (__pa (initrd_start)); } -return initrd_end; +return PFN_UP (end); }static void __init finalize_initrd (void )
@@ -223,7 +231,7 @@ disable:#else /* !CONFIG_BLK_DEV_INITRD */ -#define init_initrd () 0 +#define init_initrd () 0UL#define finalize_initrd () do {} while (0)#endif
@@ -255,8 +263,7 @@ static void __init bootmem_init(void)* not selected. Once that done we can determine the low bound * of usable memory. */ - reserved_end =init_initrd (); - reserved_end =PFN_UP (max (__pa (reserved_end),__pa_symbol (&_end))); + reserved_end =max (init_initrd (),PFN_UP (__pa_symbol (&_end)));/* * Find the highest page frame number we have available.
arch/mips/mm/init.c +0 -5
@@ -502,11 +502,6 @@ void free_init_pages(char *what, unsigne#ifdef CONFIG_BLK_DEV_INITRD void free_initrd_mem (unsigned long start,unsigned long end) { -#ifdef CONFIG_64BIT -/* Switch from KSEG0 to XKPHYS addresses */ - start = (unsigned long )phys_to_virt (CPHYSADDR (start)); - end = (unsigned long )phys_to_virt (CPHYSADDR (end)); -#endif free_init_pages ("initrd memory" , start, end); }#endif
Signature · 1 line
1.4.2.3
Re: [PATCH 6/7] setup.c: clean up initrd related code
Atsushi,
Quoted 2 lines · Franck Bui-Huu
Signed-off-by Franck Bui-Huu <[email protected]>---
[snip]
Quoted 1 line
(quoted diff) +0
-0@@ -176,24 +174,34 @@ static unsigned long __init init_initrd(
[snip]
arch/mips/kernel/setup.c static unsigned long __init init_initrd( · line 183
Quoted 5 lines
arch/mips/kernel/setup.c +0
-0end = (unsigned long )&_end; tmp =PAGE_ALIGN (end) -sizeof (u32) *2 ;if (tmp < end) tmp +=PAGE_SIZE ;
Any idea on what is this code for ?
It seems that a minimum gap is needed betweend the end of kernel code and initrd but I don't see why...
Thanks
Franck
Re: [PATCH 6/7] setup.c: clean up initrd related code
Quoted 9 lines · Franck Bui-Huu
arch/mips/kernel/setup.c static unsigned long __init init_initrd( · line 183
Quoted 5 lines
arch/mips/kernel/setup.c +0
-0end = (unsigned long )&_end; tmp =PAGE_ALIGN (end) -sizeof (u32) *2 ;if (tmp < end) tmp +=PAGE_SIZE ;Any idea on what is this code for ?
It seems that a minimum gap is needed betweend the end of kernel code and initrd but I don't see why...
Perhaps because current tools put initrd image at that place.
For example:
arch/mips/boot/addinitrd.c:92:
loadaddr = ((SWAB(esecs[2].s_vaddr) + SWAB(esecs[2].s_size) + MIPS_PAGE_SIZE-1) & ~MIPS_PAGE_MASK) - 8; if (loadaddr < (SWAB(esecs[2].s_vaddr) + SWAB(esecs[2].s_size))) loadaddr += MIPS_PAGE_SIZE; initrd_header[0] = SWAB(0x494E5244); initrd_header[1] = SWAB(st.st_size);
---
Atsushi Nemoto
Re: [PATCH 6/7] setup.c: clean up initrd related code
Quoted 14 lines · Atsushi Nemoto
Quoted 8 lines · Franck Bui-Huu
Review
Quoted 5 lines
(quoted diff) +0
-0end = (unsigned long)&_end; tmp = PAGE_ALIGN(end) - sizeof(u32) * 2; if (tmp < end) tmp += PAGE_SIZE;Any idea on what is this code for ?
It seems that a minimum gap is needed betweend the end of kernel code and initrd but I don't see why...Perhaps because current tools put initrd image at that place.
For example:
Quoted 8 lines
arch/mips/boot/addinitrd.c:92:loadaddr = ((SWAB(esecs[2].s_vaddr) + SWAB(esecs[2].s_size) + MIPS_PAGE_SIZE-1) & ~MIPS_PAGE_MASK) - 8; if (loadaddr < (SWAB(esecs[2].s_vaddr) + SWAB(esecs[2].s_size))) loadaddr += MIPS_PAGE_SIZE; initrd_header[0] = SWAB(0x494E5244); initrd_header[1] = SWAB(st.st_size);
thanks but it doesn't explain anything either...Anyways what about this patch on top of the previous one ?
-- >8 --
arch/mips/kernel/setup.c +4 -6
@@ -177,15 +177,13 @@ static unsigned long __init init_initrd(if (initrd_end > initrd_start) goto sanitize; - end = (unsigned long )&_end; - tmp =PAGE_ALIGN (end) -sizeof (u32) *2 ; -if (tmp < end) - tmp +=PAGE_SIZE ; - +/* +* FIXME: a good comment would be nice here... +*/ + initrd_header =__va (PAGE_ALIGN (__pa_symbol (&_end) +sizeof (u32) *2 +1 )); initrd_start =0 ; initrd_end =0 ; end =0 ; - initrd_header = (u32 *)tmp;if (initrd_header[0 ] ==0x494E5244 ) { initrd_start = (unsigned long )&initrd_header[2 ]; initrd_end = initrd_start + initrd_header[1 ];
Re: [PATCH 6/7] setup.c: clean up initrd related code
arch/mips/kernel/setup.c static unsigned long __init init_initrd( · line 183
Quoted 4 lines · Franck Bui-Huu
thanks but it doesn't explain anything either...Anyways what about this patch on top of the previous one ?
arch/mips/kernel/setup.c +1
-0+ initrd_header =__va (PAGE_ALIGN (__pa_symbol (&_end) +sizeof (u32) *2 +1 ));
This breaks the addinitrd. You mean this perhaps?
initrd_header = __va(PAGE_ALIGN(__pa_symbol(&_end) + sizeof(u32) * 2)) - sizeof(u32) * 2;
BTW, I'm a bit uncomfortable with current automatic initrd detection. Now we have rd_start= option. If I enabled BLK_DEV_INITRD and did pass nfsroot= instead of rd_start= option, I want kernel do not search initrd_header at all. Note that in this case current kernel might misdetect initrd_header from garbage beyond "_end".
I think something like CONFIG_INITRD_AUTODETECT to control this behaviour is useful. What do you think?
---
Atsushi Nemoto
Re: [PATCH 6/7] setup.c: clean up initrd related code
Quoted 8 lines · Atsushi Nemoto
arch/mips/kernel/setup.c static unsigned long __init init_initrd( · line 183
Quoted 4 lines · Franck Bui-Huu
thanks but it doesn't explain anything either...Anyways what about this patch on top of the previous one ?
arch/mips/kernel/setup.c +1
-0+ initrd_header =__va (PAGE_ALIGN (__pa_symbol (&_end) +sizeof (u32) *2 +1 ));This breaks the addinitrd. You mean this perhaps?
Quoted 7 lines
initrd_header=__va(PAGE_ALIGN(__pa_symbol(&_end) + sizeof(u32) * 2))- sizeof(u32) * 2;BTW, I'm a bit uncomfortable with current automatic initrd detection. Now we have rd_start= option. If I enabled
BLK_DEV_INITRDand did pass nfsroot= instead of rd_start= option, I want kernel do not searchinitrd_headerat all.
There's "noinitrd" for that purpose. Alos, one might want to use a built-in initrd plus nfsroot.
Thiemo
Re: [PATCH 6/7] setup.c: clean up initrd related code
Quoted 7 lines · Thiemo Seufer
Quoted 4 lines
BTW, I'm a bit uncomfortable with current automatic initrd detection. Now we have rd_start= option. If I enabled
BLK_DEV_INITRDand did pass nfsroot= instead of rd_start= option, I want kernel do not searchinitrd_headerat all.There's "noinitrd" for that purpose. Alos, one might want to use a built-in initrd plus nfsroot.
Yes, but "noinitrd" is checked _after_ we preserved initrd space, so if I did not initialize initrd_header area kernel might try to preserve initrd space based on garbage...
---
Atsushi Nemoto
Re: [PATCH 6/7] setup.c: clean up initrd related code
In reply to Atsushi NemotoQuoted 10 lines · Atsushi Nemoto
arch/mips/kernel/setup.c static unsigned long __init init_initrd( · line 183
Quoted 4 lines · Franck Bui-Huu
thanks but it doesn't explain anything either...Anyways what about this patch on top of the previous one ?
arch/mips/kernel/setup.c +1
-0+ initrd_header =__va (PAGE_ALIGN (__pa_symbol (&_end) +sizeof (u32) *2 +1 ));This breaks the addinitrd. You mean this perhaps?
initrd_header=__va(PAGE_ALIGN(__pa_symbol(&_end) + sizeof(u32) * 2))- sizeof(u32) * 2;
you're right, but I really don't see how this work and IMHO this code is broken.
In my mind, I was thinking that initrd_head had to be PAGE_SIZE aligned and that was the reason of that weird code...
Quoted 7 lines
BTW, I'm a bit uncomfortable with current automatic initrd detection. Now we have rd_start= option. If I enabled
BLK_DEV_INITRDand did pass nfsroot= instead of rd_start= option, I want kernel do not searchinitrd_headerat all. Note that in this case current kernel might misdetectinitrd_headerfrom garbage beyond "_end".
Well that might happen if you want a nfs rootfs but want to execute an initrd before mounting the rootfs and this initrd has been included in the kernel image with the 'addinitrd' stuff.
Quoted 3 lines
I think something like
CONFIG_INITRD_AUTODETECTto control this behaviour is useful. What do you think?
It's safer although it can be enough to check against a magic number well chosen. Maybe we can introduce a new option to the command line, 'initrd_noprobe' for example. But in any case make the default to auto detect initrd to avoid breaking some old configs.
Franck
Re: [PATCH 6/7] setup.c: clean up initrd related code
Quoted 7 lines · Franck Bui-Huu
Quoted 6 lines · Atsushi Nemoto
arch/mips/kernel/setup.c static unsigned long __init init_initrd( · line 183
Quoted 3 lines · Franck Bui-Huu
thanks but it doesn't explain anything either...Anyways what about this patch on top of the previous one ?
arch/mips/kernel/setup.c +1
-0+ initrd_header =__va (PAGE_ALIGN (__pa_symbol (&_end) +sizeof (u32) *2 +1 ));This breaks the addinitrd. You mean this perhaps?
Quoted 5 lines
Quoted 2 lines
initrd_header=__va(PAGE_ALIGN(__pa_symbol(&_end) + sizeof(u32) * 2))- sizeof(u32) * 2;you're right, but I really don't see how this work and IMHO this code is broken.
nope it's not, I just realised what is it for, see my reply to Thiemo.
Franck
Re: [PATCH 6/7] setup.c: clean up initrd related code
In reply to Franck Bui-HuuQuoted 14 lines · Franck Bui-Huu
Atsushi,
Quoted 2 lines · Franck Bui-Huu
Signed-off-by Franck Bui-Huu <[email protected]>---
[snip]
Quoted 1 line
(quoted diff) +0
-0@@ -176,24 +174,34 @@ static unsigned long __init init_initrd([snip]
arch/mips/kernel/setup.c static unsigned long __init init_initrd( · line 183
Quoted 5 lines
arch/mips/kernel/setup.c +0
-0end = (unsigned long )&_end; tmp =PAGE_ALIGN (end) -sizeof (u32) *2 ;if (tmp < end) tmp +=PAGE_SIZE ;
Quoted 3 lines
Any idea on what is this code for ?
It seems that a minimum gap is needed betweend the end of kernel code and initrd but I don't see why...
AFAIR the bootmem map is placed there.
Thiemo
Re: [PATCH 6/7] setup.c: clean up initrd related code
Quoted 14 lines · Thiemo Seufer
Quoted 13 lines · Franck Bui-Huu
Atsushi,
Quoted 2 lines · Franck Bui-Huu
Signed-off-by Franck Bui-Huu <[email protected]>---
[snip]
Quoted 1 line
(quoted diff) +0
-0@@ -176,24 +174,34 @@ static unsigned long __init init_initrd([snip]
Quoted 5 lines
arch/mips/kernel/setup.c +0
-0end = (unsigned long )&_end; tmp =PAGE_ALIGN (end) -sizeof (u32) *2 ;if (tmp < end) tmp +=PAGE_SIZE ;
Quoted 6 lines
Quoted 3 lines
Any idea on what is this code for ?
It seems that a minimum gap is needed betweend the end of kernel code and initrd but I don't see why...AFAIR the bootmem map is placed there.
boot_mem_map[] seems to be located in bss.
Franck
Re: [PATCH 6/7] setup.c: clean up initrd related code
Quoted 15 lines · Franck Bui-Huu
Quoted 14 lines · Thiemo Seufer
Quoted 13 lines · Franck Bui-Huu
Atsushi,
Quoted 2 lines · Franck Bui-Huu
Signed-off-by Franck Bui-Huu <[email protected]>---
[snip]
Quoted 1 line
(quoted diff) +0
-0@@ -176,24 +174,34 @@ static unsigned long __init init_initrd([snip]
Quoted 5 lines
arch/mips/kernel/setup.c +0
-0end = (unsigned long )&_end; tmp =PAGE_ALIGN (end) -sizeof (u32) *2 ;if (tmp < end) tmp +=PAGE_SIZE ;
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Any idea on what is this code for ?
It seems that a minimum gap is needed betweend the end of kernel code and initrd but I don't see why...AFAIR the bootmem map is placed there.
boot_mem_map[] seems to be located in bss.
ok I think I got it...
Actually sizeof(u32) * 2 is the place reserved for the initrd header and this header is right before initrd itself.
initrd_header[0] -> magic number initrd_header[1] -> size of initrd initrd start ... initrd end
and initrd start must be PAGE_SIZE aligned, surely because we free it with a page granularity.
Franck
Re: [PATCH 6/7] setup.c: clean up initrd related code
In reply to Franck Bui-HuuReview
Quoted 11 lines · Franck Bui-Huu
(quoted diff) +11
-0+sanitize: + /* + * Sanitize initrd addresses. For example firmware + * can't guess if they need to pass them through + * 64-bits values if the kernel has been built in pure + * 32-bit. We need also to switch from KSEG0 to XKPHYS + * addresses now, so the code can now safely use __pa(). + */ + end = __pa(initrd_end); + initrd_end = (unsigned long)__va(end); + initrd_start = (unsigned long)__va(__pa(initrd_start));
At last I tested whole patchset on 64-bit and see this is not enough.
If I passed 0x000000008XXXXXXX instead of 0xffffffff8XXXXXXX to initrd_start and initrd_end, the result of __pa() is not what I wanted. This is a proposal fix.
mips/kernel/setup.c renamed from mips/kernel/setup.c.orig +8 -0
@@ -199,6 +199,14 @@* 32-bit. We need also to switch from KSEG0 to XKPHYS * addresses now, so the code can now safely use __pa(). */ +#ifdef CONFIG_64BIT +/* HACK: Guess if the sign extension was forgotten */ +if (initrd_start <XKPHYS ) { + initrd_end -= initrd_start; + initrd_start = (int )initrd_start; + initrd_end += initrd_start; + } +#endif end =__pa (initrd_end); initrd_end = (unsigned long )__va (end); initrd_start = (unsigned long )__va (__pa (initrd_start));
With this fix and __pa() fix in my previous mail, your patchset works well on my 64-bit kernel. Thanks.
---
Atsushi Nemoto
Re: [PATCH 6/7] setup.c: clean up initrd related code
Quoted 6 lines · Atsushi Nemoto
Review
Quoted 3 lines · Franck Bui-Huu
(quoted diff) +3
-0+ end = __pa(initrd_end); + initrd_end = (unsigned long)__va(end); + initrd_start = (unsigned long)__va(__pa(initrd_start));At last I tested whole patchset on 64-bit and see this is not enough.
Thanks for testing. You're right this is not enough since CPHYSADDR() is not used anymore by __pa(). That shows that usage of __va(__pa(x)) construction to sanitize sign extension was weak since it relied on __pa() implementation. My own fault...
Quoted 5 lines
If I passed 0x000000008XXXXXXX instead of 0xffffffff8XXXXXXX to
initrd_startandinitrd_end, the result of__pa()is not what I wanted. This is a proposal fix.
I would rather move this fix into initrd start setup function as it was done by old code. We know that some bootloaders forget sign extension on 64 bits kernel. But if for example the sign extension is forgotten by a board specific code, we shouldn't automatically fix the mistake, but rather fix the board specific code. So I would do instead of your fix:
Quoted 10 lines
mips/kernel/setup.c 2006-10-19 13:06:39.000000000 +0900 renamed from mips/kernel/setup.c.orig 2006-10-19 11:31:12.000000000 +0900 +4
-0@@ -199,6 +199,14 @@ * 32-bit. We need also to switch from KSEG0 to XKPHYS * addresses now, so the code can now safely use __pa(). */ +#ifdef CONFIG_64BIT + if (initrd_start < XKPHYS) + panic("initrd start (%08lx) < XKPHYS", initrd_start); +#endif
Signature · 1 line
Franck
Re: [PATCH 6/7] setup.c: clean up initrd related code
Quoted 6 lines · Franck Bui-Huu
I would rather move this fix into initrd start setup function as it was done by old code. We know that some bootloaders forget sign extension on 64 bits kernel. But if for example the sign extension is forgotten by a board specific code, we shouldn't automatically fix the mistake, but rather fix the board specific code. So I would do instead of your fix:
But we need sign extension for values comes from the initrd_header anyway. The initrd_header is fixed-size and can not hold 64-bit address.
---
Atsushi Nemoto
Re: [PATCH 6/7] setup.c: clean up initrd related code
Quoted 8 lines · Atsushi Nemoto
Quoted 6 lines · Franck Bui-Huu
I would rather move this fix into initrd start setup function as it was done by old code. We know that some bootloaders forget sign extension on 64 bits kernel. But if for example the sign extension is forgotten by a board specific code, we shouldn't automatically fix the mistake, but rather fix the board specific code. So I would do instead of your fix:
Quoted 4 lines
But we need sign extension for values comes from the
initrd_headeranyway. Theinitrd_headeris fixed-size and can not hold 64-bit address.
initrd_header gives only 2 numbers: size of initrd, and a magic number, well it's what I understood when rewriting the code.
the start address of initrd is given by:
initrd_header = __va(PAGE_ALIGN(__pa_symbol(&_end) + 8)) - 8; initrd_start = (unsigned long)&initrd_header[2];
I don't think we need any sign extension here, do we ?
Franck
Re: [PATCH 6/7] setup.c: clean up initrd related code
Quoted 8 lines · Franck Bui-Huu
Quoted 4 lines
But we need sign extension for values comes from the
initrd_headeranyway. Theinitrd_headeris fixed-size and can not hold 64-bit address.
initrd_headergives only 2 numbers: size of initrd, and a magic number, well it's what I understood when rewriting the code.
Quoted 6 lines
the start address of initrd is given by:
initrd_header = __va(PAGE_ALIGN(__pa_symbol(&_end) + 8)) - 8; initrd_start = (unsigned long)&initrd_header[2];I don't think we need any sign extension here, do we ?
Oh I was confused. You are right.
BTW, we can just ignore initrd instead of panic() if invalid values given. This place around is too early to print panic message. Continuing with printk(KERN_ERR) will give us a chance to see what's wrong.
---
Atsushi Nemoto
Re: [PATCH 6/7] setup.c: clean up initrd related code
Quoted 8 lines · Atsushi Nemoto
Quoted 7 lines · Franck Bui-Huu
Quoted 4 lines
But we need sign extension for values comes from the
initrd_headeranyway. Theinitrd_headeris fixed-size and can not hold 64-bit address.
initrd_headergives only 2 numbers: size of initrd, and a magic number, well it's what I understood when rewriting the code.
Quoted 8 lines
Quoted 6 lines
the start address of initrd is given by:
initrd_header = __va(PAGE_ALIGN(__pa_symbol(&_end) + 8)) - 8;I don't think we need any sign extension here, do we ?
Oh I was confused. You are right.
yeah I was confused at the first look too. I think rewriting it like this:
initrd_start = (unsigned long)(initrd_header + 2);
is less confusing...
Quoted 6 lines
BTW, we can just ignore initrd instead of
panic()if invalid values given. This place around is too early to print panic message. Continuing withprintk(KERN_ERR)will give us a chance to see what's wrong.
ok, I'm rebuilding a new patchset and sending it pretty soon,
Franck
Re: [PATCH 6/7] setup.c: clean up initrd related code
In reply to Atsushi NemotoQuoted 23 lines · Atsushi Nemoto
Review
Quoted 11 lines · Franck Bui-Huu
(quoted diff) +11
-0+sanitize: + /* + * Sanitize initrd addresses. For example firmware + * can't guess if they need to pass them through + * 64-bits values if the kernel has been built in pure + * 32-bit. We need also to switch from KSEG0 to XKPHYS + * addresses now, so the code can now safely use __pa(). + */ + end = __pa(initrd_end); + initrd_end = (unsigned long)__va(end); + initrd_start = (unsigned long)__va(__pa(initrd_start));At last I tested whole patchset on 64-bit and see this is not enough.
If I passed 0x000000008XXXXXXX instead of 0xffffffff8XXXXXXX to
initrd_startandinitrd_end, the result of__pa()is not what I wanted. This is a proposal fix.mips/kernel/setup.c renamed from mips/kernel/setup.c.orig +0
-0@@ -199,6 +199,14 @@* 32-bit. We need also to switch from KSEG0 to XKPHYS
mips/kernel/setup.c line 209
Quoted 10 lines
mips/kernel/setup.c renamed from mips/kernel/setup.c.orig +8
-0* addresses now, so the code can now safely use __pa(). */ +#ifdef CONFIG_64BIT +/* HACK: Guess if the sign extension was forgotten */ +if (initrd_start <XKPHYS ) { + initrd_end -= initrd_start; + initrd_start = (int )initrd_start; + initrd_end += initrd_start; + } +#endif
BTW, what about this condition:
if (initrd_start < PAGE_OFFSET) {
...;
}that would work even on 32 bits kernel.
Franck
Re: [PATCH 6/7] setup.c: clean up initrd related code
Quoted 11 lines · Franck Bui-Huu
mips/kernel/setup.c line 209
Quoted 8 lines
mips/kernel/setup.c renamed from mips/kernel/setup.c.orig +8
-0+#ifdef CONFIG_64BIT +/* HACK: Guess if the sign extension was forgotten */ +if (initrd_start <XKPHYS ) { + initrd_end -= initrd_start; + initrd_start = (int )initrd_start; + initrd_end += initrd_start; + } +#endif BTW, what about this condition:
Quoted 5 lines
if (initrd_start < PAGE_OFFSET) { ...; }that would work even on 32 bits kernel.
This does not work if PAGE_OFFSET was 0xffffffff80000000 and initrd_start was 0x980000000XXXXXXX :-)
if ((long)initrd_start >= 0) {
would work.
---
Atsushi Nemoto
Re: [PATCH 6/7] setup.c: clean up initrd related code
Quoted 12 lines · Atsushi Nemoto
Quoted 7 lines · Franck Bui-Huu
BTW, what about this condition:
if (initrd_start < PAGE_OFFSET) { ...; }that would work even on 32 bits kernel.
This does not work if
PAGE_OFFSETwas0xffffffff80000000andinitrd_startwas 0x980000000XXXXXXX :-)
I think we should terminate this patch pretty quickly because it's going to make me mad ;)
How can PAGE_OFFSET be in CKSEG0 segment and initrd_start be in XKPHYS ?
With the current code we can say:
- If PAGE_OFFSET is in CKSEG0, that means that all kernel virtual address must be in CKSEG0.
- If PAGE_OFFSET is in XKPHYS, that means that _after_ booting process all kernel virtual address will be in XKPHYS. But we allow CKSEG0 virtual address during boot for the reasons we know.
What woud give __pa(initrd_start) in your example ?
__pa(initrd_start) -> 0x980000000XXXXXXX - 0xffffffff80000000
which is wrong...Does your example come from a real use case ?
Franck
Re: [PATCH 6/7] setup.c: clean up initrd related code
Quoted 9 lines · Franck Bui-Huu
Quoted 3 lines
This does not work if
PAGE_OFFSETwas0xffffffff80000000andinitrd_startwas 0x980000000XXXXXXX :-)I think we should terminate this patch pretty quickly because it's going to make me mad ;)
How can
PAGE_OFFSETbe in CKSEG0 segment andinitrd_startbe in XKPHYS ?
If we passed a XKPHYS address to "rd_start=" option. Bad usage :-)
Quoted 9 lines
With the current code we can say:
- If
PAGE_OFFSETis in CKSEG0, that means that all kernel virtual address must be in CKSEG0.
- IfPAGE_OFFSETis in XKPHYS, that means that _after_ booting process all kernel virtual address will be in XKPHYS. But we allow CKSEG0 virtual address during boot for the reasons we know.
Quoted 5 lines
What woud give
__pa(initrd_start)in your example ?
__pa(initrd_start)-> 0x980000000XXXXXXX -0xffffffff80000000which is wrong...Does your example come from a real use case ?
It's wrong indeed. But I can not see good way to handle such terrible usage. So ... let's ignore it. I'm OK, are you ?
---
Atsushi Nemoto
Re: [PATCH 6/7] setup.c: clean up initrd related code
Quoted 4 lines · Atsushi Nemoto
Quoted 3 lines · Franck Bui-Huu
Quoted 3 lines
This does not work if
PAGE_OFFSETwas0xffffffff80000000andinitrd_startwas 0x980000000XXXXXXX :-)
Quoted 8 lines
Quoted 5 lines
I think we should terminate this patch pretty quickly because it's going to make me mad ;)
How can
PAGE_OFFSETbe in CKSEG0 segment andinitrd_startbe in XKPHYS ?If we passed a XKPHYS address to "rd_start=" option. Bad usage :-)
ok so testing initrd_start against PAGE_OFFSET (instead of XKPHYS) is good check since we catch such bad usages. Do you agree ?
Quoted 9 lines
Quoted 9 lines
With the current code we can say:
- If
PAGE_OFFSETis in CKSEG0, that means that all kernel virtual address must be in CKSEG0.
- IfPAGE_OFFSETis in XKPHYS, that means that _after_ booting process all kernel virtual address will be in XKPHYS. But we allow CKSEG0 virtual address during boot for the reasons we know.
Quoted 9 lines
Quoted 5 lines
What woud give
__pa(initrd_start)in your example ?
__pa(initrd_start)-> 0x980000000XXXXXXX -0xffffffff80000000which is wrong...Does your example come from a real use case ?
It's wrong indeed. But I can not see good way to handle such terrible usage. So ... let's ignore it. I'm OK, are you ?
why do we need to handle them anyway ?
PAGE_OFFSET in XKPHYS means that the kernel runs in XKPHYS address space. We allow at boot time kernel address to be in CKSEG0 because we have a good reason to handle that. It allows to get a kernel smaller and faster at compile time.
PAGE_OFFSET in CKSEG0 means that the kernel runs in CKSEG0 address space. This means also that kernel can't handle XKPHYS address. But how would the kernel get addresses in XKPHYS (except user bad usages) ?
Franck
Re: [PATCH 6/7] setup.c: clean up initrd related code
Quoted 4 lines · Franck Bui-Huu
Quoted 1 line
If we passed a XKPHYS address to "rd_start=" option. Bad usage :-)
ok so testing
initrd_startagainstPAGE_OFFSET(instead of XKPHYS) is good check since we catch such bad usages. Do you agree ?
Yes.
Quoted 5 lines
Quoted 2 lines
It's wrong indeed. But I can not see good way to handle such terrible usage. So ... let's ignore it. I'm OK, are you ?
why do we need to handle them anyway ?
Quoted 8 lines
PAGE_OFFSETin XKPHYS means that the kernel runs in XKPHYS address space. We allow at boot time kernel address to be in CKSEG0 because we have a good reason to handle that. It allows to get a kernel smaller and faster at compile time.
PAGE_OFFSETin CKSEG0 means that the kernel runs in CKSEG0 address space. This means also that kernel can't handle XKPHYS address. But how would the kernel get addresses in XKPHYS (except user bad usages) ?
Sure. No reason. Excuse me for such a bad example ;)
---
Atsushi Nemoto
Re: [PATCH 6/7] setup.c: clean up initrd related code
Quoted 2 lines · Atsushi Nemoto
Sure. No reason. Excuse me for such a bad example ;)
no problem, your feedbacks are always welcome.
Franck
PATCH 7/7 Make free_init_pages() arguments to be physical addresses
In reply to Franck Bui-HuuIt allows caller of this function to not care about CKSEG0/XKPHYS address mixes. It's now automatically done by free_init_pages().
We can now safely remove hack needed by 64 bit kernels with CONFIG_BUILD_ELF64=n in free_initmem().
--- arch/mips/mm/init.c | 33 +++++++++++++++++---------------- 1 files changed, 17 insertions(+), 16 deletions(-)
arch/mips/mm/init.c +17 -16
@@ -485,15 +485,18 @@ #endif }#endif /* !CONFIG_NEED_MULTIPLE_NODES */ -void free_init_pages (char *what,unsigned long begin,unsigned long end) +static void free_init_pages (char *what,unsigned long begin,unsigned long end) { -unsigned long addr; +unsigned long pfn; -for (addr = begin; addr < end; addr +=PAGE_SIZE ) { -ClearPageReserved (virt_to_page ((void *)addr)); -init_page_count (virt_to_page ((void *)addr)); -memset ((void *)addr,0xcc ,PAGE_SIZE ); -free_page (addr); +for (pfn =PFN_UP (begin); pfn <PFN_DOWN (end); pfn++) { +struct page *page =pfn_to_page (pfn); +void *addr =phys_to_virt (PFN_PHYS (pfn)); + +ClearPageReserved (page); +init_page_count (page); +memset (addr,POISON_FREE_INITMEM ,PAGE_SIZE ); +__free_page (page); totalram_pages++; }printk (KERN_INFO "Freeing %s: %ldk freed\n" , what, (end - begin) >>10 );
@@ -502,7 +505,9 @@ void free_init_pages(char *what, unsigne#ifdef CONFIG_BLK_DEV_INITRD void free_initrd_mem (unsigned long start,unsigned long end) { -free_init_pages ("initrd memory" , start, end); +free_init_pages ("initrd memory" , +virt_to_phys (start), +virt_to_phys (end)); }#endif
@@ -510,17 +515,13 @@ extern unsigned long prom_free_prom_memovoid free_initmem (void ) { -unsigned long start, end, freed; +unsigned long freed; freed =prom_free_prom_memory ();if (freed)printk (KERN_INFO "Freeing firmware memory: %ldk freed\n" ,freed); - start = (unsigned long )(&__init_begin); - end = (unsigned long )(&__init_end); -#ifdef CONFIG_64BIT - start =PAGE_OFFSET |CPHYSADDR (start); - end =PAGE_OFFSET |CPHYSADDR (end); -#endif -free_init_pages ("unused kernel memory" , start, end); +free_init_pages ("unused kernel memory" , +__pa_symbol (&__init_begin), +__pa_symbol (&__init_end)); }
Signature · 1 line
1.4.2.3
Re: [PATCH 7/7] Make free_init_pages() arguments to be physical addresses
Franck Bui-Huu wrote:
[snip]
Review
Quoted 7 lines
void
free_initrd_mem(unsigned long start, unsigned long end){(quoted diff) +3
-1- free_init_pages("initrd memory", start, end); + free_init_pages("initrd memory", + virt_to_phys(start), + virt_to_phys(end)); }
argh, this part generates warnings... please consider the patch below instead.
-- >8 --
Subject: [PATCH 7/7] Make free_init_pages() arguments to be physical addresses
It allows caller of this function to not care about CKSEG0/XKPHYS address mixes. It's now automatically done by free_init_pages().
We can now safely remove hack needed by 64 bit kernels with CONFIG_BUILD_ELF64=n in free_initmem().
--- arch/mips/mm/init.c | 33 +++++++++++++++++---------------- 1 files changed, 17 insertions(+), 16 deletions(-)
arch/mips/mm/init.c +17 -16
@@ -485,15 +485,18 @@ #endif }#endif /* !CONFIG_NEED_MULTIPLE_NODES */ -void free_init_pages (char *what,unsigned long begin,unsigned long end) +static void free_init_pages (char *what,unsigned long begin,unsigned long end) { -unsigned long addr; +unsigned long pfn; -for (addr = begin; addr < end; addr +=PAGE_SIZE ) { -ClearPageReserved (virt_to_page ((void *)addr)); -init_page_count (virt_to_page ((void *)addr)); -memset ((void *)addr,0xcc ,PAGE_SIZE ); -free_page (addr); +for (pfn =PFN_UP (begin); pfn <PFN_DOWN (end); pfn++) { +struct page *page =pfn_to_page (pfn); +void *addr =phys_to_virt (PFN_PHYS (pfn)); + +ClearPageReserved (page); +init_page_count (page); +memset (addr,POISON_FREE_INITMEM ,PAGE_SIZE ); +__free_page (page); totalram_pages++; }printk (KERN_INFO "Freeing %s: %ldk freed\n" , what, (end - begin) >>10 );
@@ -502,7 +505,9 @@ void free_init_pages(char *what, unsigne#ifdef CONFIG_BLK_DEV_INITRD void free_initrd_mem (unsigned long start,unsigned long end) { -free_init_pages ("initrd memory" , start, end); +free_init_pages ("initrd memory" , +virt_to_phys ((void *)start), +virt_to_phys ((void *)end)); }#endif
@@ -510,17 +515,13 @@ extern unsigned long prom_free_prom_memovoid free_initmem (void ) { -unsigned long start, end, freed; +unsigned long freed; freed =prom_free_prom_memory ();if (freed)printk (KERN_INFO "Freeing firmware memory: %ldk freed\n" ,freed); - start = (unsigned long )(&__init_begin); - end = (unsigned long )(&__init_end); -#ifdef CONFIG_64BIT - start =PAGE_OFFSET |CPHYSADDR (start); - end =PAGE_OFFSET |CPHYSADDR (end); -#endif -free_init_pages ("unused kernel memory" , start, end); +free_init_pages ("unused kernel memory" , +__pa_symbol (&__init_begin), +__pa_symbol (&__init_end)); }
Signature · 1 line
1.4.2.3