Fix virt_to_phys() warnings
Subsystems (4)
PATCH 1/1 Fix virt_to_phys() warnings
These warnings were observed on MIPS32 using 2.6.31-rc1 and gcc-4.2.0:
mm/page_alloc.c: In function 'alloc_pages_exact':mm/page_alloc.c:1986: warning: passing argument 1 of 'virt_to_phys' makes pointer from integer without a cast
drivers/usb/mon/mon_bin.c: In function 'mon_alloc_buff':drivers/usb/mon/mon_bin.c:1264: warning: passing argument 1 of 'virt_to_phys' makes pointer from integer without a cast
---
drivers/usb/mon/mon_bin.c +1 -1
@@ -1261,7 +1261,7 @@ static int mon_alloc_buff(struct mon_pgmap *map, int npages)return -ENOMEM ; } map[n].ptr = (unsigned char *) vaddr; - map[n].pg =virt_to_page (vaddr); + map[n].pg =virt_to_page ((void *) vaddr); }return 0 ; }
mm/page_alloc.c +1 -1
@@ -1983,7 +1983,7 @@ void *alloc_pages_exact(size_t size, gfp_t gfp_mask)unsigned long alloc_end = addr + (PAGE_SIZE << order);unsigned long used = addr +PAGE_ALIGN (size); -split_page (virt_to_page (addr), order); +split_page (virt_to_page ((void *)addr), order);while (used < alloc_end) {free_page (used); used +=PAGE_SIZE ;
--
Andrew Morton
maintainerQuoted 28 lines · On Fri, 26 Jun 2009 17:13:20 -0700 Kevin Cernekee <[email protected]> wrote:
These warnings were observed on MIPS32 using 2.6.31-rc1 and gcc-4.2.0:
mm/page_alloc.c: In function 'alloc_pages_exact':mm/page_alloc.c:1986: warning: passing argument 1 of 'virt_to_phys' makes pointer from integer without a cast
drivers/usb/mon/mon_bin.c: In function 'mon_alloc_buff':drivers/usb/mon/mon_bin.c:1264: warning: passing argument 1 of 'virt_to_phys' makes pointer from integer without a castSigned-off-by Kevin Cernekee <[email protected]>---
drivers/usb/mon/mon_bin.c +1
-1@@ -1261,7 +1261,7 @@ static int mon_alloc_buff(struct mon_pgmap *map, int npages)return -ENOMEM ; } map[n].ptr = (unsigned char *) vaddr; - map[n].pg =virt_to_page (vaddr); + map[n].pg =virt_to_page ((void *) vaddr); }return 0 ; }mm/page_alloc.c +0
-0
mm/page_alloc.c void *alloc_pages_exact(size_t size, gfp_t gfp_mask) · line 1989
Quoted 8 lines
mm/page_alloc.c +1
-1@@ -1983,7 +1983,7 @@ void *alloc_pages_exact(size_t size, gfp_t gfp_mask)unsigned long alloc_end = addr + (PAGE_SIZE << order);unsigned long used = addr +PAGE_ALIGN (size); -split_page (virt_to_page (addr), order); +split_page (virt_to_page ((void *)addr), order);while (used < alloc_end) {free_page (used); used +=PAGE_SIZE ;
The virt_to_foo() functions were written back in the Linux dark ages and they're horrid. A byzantine mixture of macros and typecasts which make it really hard to work out what type their argument actually should be.
virt_to_page() takes an argument of type `unsigned long'. (except for the include/asm-generic/page.h version which takes any damn type at all).
virt_to_phys() takes an argument of `const void *' (weird, huh?)
But arch/mips/include/asm/page.h does
#define virt_to_page(kaddr) pfn_to_page(PFN_DOWN(virt_to_phys(kaddr)))
thereby passing an `unsigned long' where a void* was expected.
So perhaps something along these lines:
arch/mips/include/asm/page.h renamed from arch/mips/include/asm/page.h~a +5 -1
@@ -184,7 +184,11 @@ typedef struct { unsigned long pgprot; }#endif -#define virt_to_page (kaddr) pfn_to_page(PFN_DOWN(virt_to_phys(kaddr))) +static inline struct page *virt_to_page (unsigned long kaddr) +{ +return pfn_to_page (PFN_DOWN (virt_to_phys ((void *)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 | \
_
Quoted 7 lines · Andrew Morton
#define
virt_to_page(kaddr)pfn_to_page(PFN_DOWN(virt_to_phys(kaddr)))thereby passing an `unsigned long' where a void* was expected.
So perhaps something along these lines:
I'm not quite sure it's the case on MIPS, but I remember on x86 one of the reasons this was done as a macro was to avoid a include dependency loop with struct page.
-Andi
Signature · 1 line
[email protected] -- Speaking for myself only.
Quoted 12 lines · Andi Kleen
From: Andi Kleen <[email protected]>
Date: Thu, 02 Jul 2009 09:07:46 +0200
To: Andrew Morton <[email protected]>
Cc: Kevin Cernekee <[email protected]>, [email protected],
Ralf Baechle <[email protected]>
Subject: Re: [PATCH] Fixvirt_to_phys()warnings
Content-Type: text/plain; charset=us-asciiQuoted 3 lines · Andrew Morton
#define
virt_to_page(kaddr)pfn_to_page(PFN_DOWN(virt_to_phys(kaddr)))
Quoted 8 lines
Quoted 4 lines
thereby passing an `unsigned long' where a void* was expected.
So perhaps something along these lines:
I'm not quite sure it's the case on MIPS, but I remember on x86 one of the reasons this was done as a macro was to avoid a include dependency loop with struct page.
The MIPS <asm/page.h> uses a forward declaration for the same reason since a very long time. These days struct page is defined in <linux/mm_types.h> but that file needs pgprot_t (which is defined in <asm/page.h> ...) to be defined first so can't be included from the to of page.h.
Ralf
Quoted 29 lines · Andrew Morton
Quoted 29 lines
mm/page_alloc.c: In function 'alloc_pages_exact':mm/page_alloc.c:1986: warning: passing argument 1 of 'virt_to_phys' makes pointer from integer without a cast
drivers/usb/mon/mon_bin.c: In function 'mon_alloc_buff':drivers/usb/mon/mon_bin.c:1264: warning: passing argument 1 of 'virt_to_phys' makes pointer from integer without a castSigned-off-by Kevin Cernekee <[email protected]>---
drivers/usb/mon/mon_bin.c +1
-1@@ -1261,7 +1261,7 @@ static int mon_alloc_buff(struct mon_pgmap *map, int npages)return -ENOMEM ; } map[n].ptr = (unsigned char *) vaddr; - map[n].pg =virt_to_page (vaddr); + map[n].pg =virt_to_page ((void *) vaddr); }return 0 ; }mm/page_alloc.c +0
-0@@ -1983,7 +1983,7 @@ void *alloc_pages_exact(size_t size, gfp_t gfp_mask)unsigned long alloc_end = addr + (PAGE_SIZE << order);unsigned long used = addr +PAGE_ALIGN (size);
Quoted 9 lines
mm/page_alloc.c void *alloc_pages_exact(size_t size, gfp_t gfp_mask) · line 1989
Quoted 5 lines
mm/page_alloc.c +1
-1-split_page (virt_to_page (addr), order); +split_page (virt_to_page ((void *)addr), order);while (used < alloc_end) {free_page (used); used +=PAGE_SIZE ;The
virt_to_foo()functions were written back in the Linux dark ages and they're horrid. A byzantine mixture of macros and typecasts which make it really hard to work out what type their argument actually should be.
No disagreement there.
Quoted 3 lines
virt_to_page()takes an argument of type `unsigned long'. (except for theinclude/asm-generic/page.hversion which takes any damn type at all).
You meant it takes a pointer argument, for example:
mm/page_alloc.c:
__free_pages(virt_to_page((void *)addr), order);
mm/slob.c:
static inline struct slob_page *slob_page(const void *addr)
{
return (struct slob_page *)virt_to_page(addr);
}Quoted 1 line
virt_to_phys()takes an argument of `const void *' (weird, huh?)
volatile void * seems to be the most common type. MIPS is the only arch that accepts volatile const void *; Alpha uses a plain void *.
I don't recall why MIPS uses volatile const - probably to silence warnings about discarding qualifiers from pointer target type.
Quoted 13 lines
But
arch/mips/include/asm/page.hdoes#define
virt_to_page(kaddr)pfn_to_page(PFN_DOWN(virt_to_phys(kaddr)))thereby passing an `unsigned long' where a void* was expected.
So perhaps something along these lines:
arch/mips/include/asm/page.h typedef struct { unsigned long pgprot; } · line 191
Quoted 9 lines
arch/mips/include/asm/page.h renamed from arch/mips/include/asm/page.h~a +5
-1@@ -184,7 +184,11 @@ typedef struct { unsigned long pgprot; }#endif -#define virt_to_page (kaddr) pfn_to_page(PFN_DOWN(virt_to_phys(kaddr))) +static inline struct page *virt_to_page (unsigned long kaddr) +{ +return pfn_to_page (PFN_DOWN (virt_to_phys ((void *)kaddr))); +} +
Doesn't compile because pfn_to_page is defined in <asm-generic/memory_model.h> which will only be included further down and moving the order of the order of things around to get this to build is getting ugly, so I gave up on it.
Anyway, since virt_to_page and virt_to_phys (imho :-) take the same argument times I'm in favor of Kevin's patch.
Ralf
Andrew Morton
maintainerQuoted 49 lines · On Thu, 2 Jul 2009 11:40:27 +0100 Ralf Baechle <[email protected]> wrote:
Quoted 29 lines · Andrew Morton
Quoted 29 lines
mm/page_alloc.c: In function 'alloc_pages_exact':mm/page_alloc.c:1986: warning: passing argument 1 of 'virt_to_phys' makes pointer from integer without a cast
drivers/usb/mon/mon_bin.c: In function 'mon_alloc_buff':drivers/usb/mon/mon_bin.c:1264: warning: passing argument 1 of 'virt_to_phys' makes pointer from integer without a castSigned-off-by Kevin Cernekee <[email protected]>---
drivers/usb/mon/mon_bin.c +1
-1@@ -1261,7 +1261,7 @@ static int mon_alloc_buff(struct mon_pgmap *map, int npages)return -ENOMEM ; } map[n].ptr = (unsigned char *) vaddr; - map[n].pg =virt_to_page (vaddr); + map[n].pg =virt_to_page ((void *) vaddr); }return 0 ; }mm/page_alloc.c +0
-0@@ -1983,7 +1983,7 @@ void *alloc_pages_exact(size_t size, gfp_t gfp_mask)unsigned long alloc_end = addr + (PAGE_SIZE << order);unsigned long used = addr +PAGE_ALIGN (size);Quoted 9 lines
mm/page_alloc.c void *alloc_pages_exact(size_t size, gfp_t gfp_mask) · line 1989
Quoted 5 lines
mm/page_alloc.c +1
-1-split_page (virt_to_page (addr), order); +split_page (virt_to_page ((void *)addr), order);while (used < alloc_end) {free_page (used); used +=PAGE_SIZE ;The
virt_to_foo()functions were written back in the Linux dark ages and they're horrid. A byzantine mixture of macros and typecasts which make it really hard to work out what type their argument actually should be.No disagreement there.
Quoted 3 lines
virt_to_page()takes an argument of type `unsigned long'. (except for theinclude/asm-generic/page.hversion which takes any damn type at all).You meant it takes a pointer argument, for example:
Quoted 8 lines
mm/page_alloc.c:__free_pages(virt_to_page((void *)addr), order); mm/slob.c: static inline struct slob_page *slob_page(const void *addr) { return (struct slob_page *)virt_to_page(addr); }
lol. I think you're right. What a crock.
looky, they're popping up everywhere:
: static void perf_mmap_free_page(unsigned long addr) : {
: struct page *page = virt_to_page(addr);
:
And mm/nommu.c:
: int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
: unsigned long start, int nr_pages, int flags,
: struct page **pages, struct vm_area_struct **vmas)
: {
: ...
: pages[i] = virt_to_page(start);
: static void free_page_series(unsigned long from, unsigned long to) : {
: for (; from < to; from += PAGE_SIZE) {
: struct page *page = virt_to_page(from);
Heaven knows how many more there are. I guess we should drag x86's virt_to_page()/virt_to_phys() into the 1980's by doing some compile-time arg checking?
Quoted 5 lines
...
Anyway, since
virt_to_pageandvirt_to_phys(imho :-) take the same argument times I'm in favor of Kevin's patch.
yup, I'll queue it.