Skip to contentSkip to conversation

2.6.28, vmalloc.c, vmap_page_range

PATCH In review Adam Lackorzynski 4 participants 6 messages Dec 25, 2008 – Dec 27, 2008

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

PATCH 1/1 2.6.28, vmalloc.c, vmap_page_range

Hi,

in 2.6.28, the flush_cache_vmap in vmap_page_range() is called with the end of the range twice. The following patch fixes this for me.

---
 vmalloc.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/vmalloc.c +2 -2
@@ -155,7 +155,7 @@
 				pgprot_t prot, struct page **pages)
 {
 	pgd_t *pgd;
-	unsigned long next;
+	unsigned long next, start = addr;
 	int err = 0;
 	int nr = 0;
 
@@ -167,7 +167,7 @@
 		if (err)
 			break;
 	} while (pgd++, addr = next, addr != end);
-	flush_cache_vmap(addr, end);
+	flush_cache_vmap(start, end);
 
 	if (unlikely(err))
 		return err;

Adam

Signature · 2 lines
Adam                 [email protected]
  Lackorzynski         http://os.inf.tu-dresden.de/~adam/
maintainer
#1 lore raw
Quoted 5 lines · On Thu, 25 Dec 2008 22:02:35 +0100 Adam Lackorzynski…

Hi,

in 2.6.28, the flush_cache_vmap in vmap_page_range() is called with the end of the range twice. The following patch fixes this for me.

Did this bug have any observeable runtime effects? If so, what were they?

Quoted 16 lines
---
 vmalloc.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/vmalloc.c +1 -1
@@ -155,7 +155,7 @@
 				pgprot_t prot, struct page **pages)
 {
 	pgd_t *pgd;
-	unsigned long next;
+	unsigned long next, start = addr;
 	int err = 0;
 	int nr = 0;
 

mm/vmalloc.c line 173

Quoted 8 lines
mm/vmalloc.c +1 -1
@@ -167,7 +167,7 @@
 		if (err)
 			break;
 	} while (pgd++, addr = next, addr != end);
-	flush_cache_vmap(addr, end);
+	flush_cache_vmap(start, end);
 
 	if (unlikely(err))
 		return err;

Well yeah. This is what happens when functions modify their incoming arguments. It's a bad programming practice which leads directly to exactly this sort of bug.

How about we fix that?

mm/vmalloc.c renamed from mm/vmalloc.c~vmallocc-fix-flushing-in-vmap_page_range +3 -2
@@ -151,11 +151,12 @@ static int vmap_pud_range(pgd_t *pgd, un
  *
  * Ie. pte at addr+N*PAGE_SIZE shall point to pfn corresponding to pages[N]
  */
-static int vmap_page_range(unsigned long addr, unsigned long end,
+static int vmap_page_range(unsigned long start_addr, unsigned long end,
 				pgprot_t prot, struct page **pages)
 {
 	pgd_t *pgd;
 	unsigned long next;
+	unsigned long addr = start_addr;
 	int err = 0;
 	int nr = 0;
 
@@ -167,7 +168,7 @@ static int vmap_page_range(unsigned long
 		if (err)
 			break;
 	} while (pgd++, addr = next, addr != end);
-	flush_cache_vmap(addr, end);
+	flush_cache_vmap(start_addr, end);
 
 	if (unlikely(err))
 		return err;

_

#2 lore raw
Quoted 46 lines · Andrew Morton
Quoted 5 lines · On Thu, 25 Dec 2008 22:02:35 +0100 Adam Lackorzynski…

Hi,

in 2.6.28, the flush_cache_vmap in vmap_page_range() is called with the end of the range twice. The following patch fixes this for me.

Did this bug have any observeable runtime effects? If so, what were they?

Quoted 16 lines
---
 vmalloc.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/vmalloc.c +1 -1
@@ -155,7 +155,7 @@
 				pgprot_t prot, struct page **pages)
 {
 	pgd_t *pgd;
-	unsigned long next;
+	unsigned long next, start = addr;
 	int err = 0;
 	int nr = 0;
 

mm/vmalloc.c line 173

Quoted 8 lines
mm/vmalloc.c +1 -1
@@ -167,7 +167,7 @@
 		if (err)
 			break;
 	} while (pgd++, addr = next, addr != end);
-	flush_cache_vmap(addr, end);
+	flush_cache_vmap(start, end);
 
 	if (unlikely(err))
 		return err;

Well yeah. This is what happens when functions modify their incoming arguments. It's a bad programming practice which leads directly to exactly this sort of bug.

How about we fix that?

mm/vmalloc.c static int vmap_pud_range(pgd_t *pgd, un · line 159

Quoted 10 lines
mm/vmalloc.c renamed from mm/vmalloc.c~vmallocc-fix-flushing-in-vmap_page_range +2 -1
@@ -151,11 +151,12 @@ static int vmap_pud_range(pgd_t *pgd, un
  *
  * Ie. pte at addr+N*PAGE_SIZE shall point to pfn corresponding to pages[N]
  */
-static int vmap_page_range(unsigned long addr, unsigned long end,
+static int vmap_page_range(unsigned long start_addr, unsigned long end,
 				pgprot_t prot, struct page **pages)
 {
 	pgd_t *pgd;
 	unsigned long next;
+	unsigned long addr = start_addr;

Ugh, start_addr is an awful name. How about start? I know it doesn't hold the same amount of information but it's a local API, the pgd_offset_k() should make the unit unambiguous, it goes better with the end parameter and it's unique enough for this short function.

Hannes

#3 lore raw
Quoted 54 lines · Johannes Weiner
Quoted 53 lines · Andrew Morton
Quoted 5 lines · On Thu, 25 Dec 2008 22:02:35 +0100 Adam Lackorzynski…

Hi,

in 2.6.28, the flush_cache_vmap in vmap_page_range() is called with the end of the range twice. The following patch fixes this for me.

Did this bug have any observeable runtime effects? If so, what were they?

Quoted 16 lines
---
 vmalloc.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
mm/vmalloc.c +1 -1
@@ -155,7 +155,7 @@
 				pgprot_t prot, struct page **pages)
 {
 	pgd_t *pgd;
-	unsigned long next;
+	unsigned long next, start = addr;
 	int err = 0;
 	int nr = 0;
 

mm/vmalloc.c line 173

Quoted 8 lines
mm/vmalloc.c +1 -1
@@ -167,7 +167,7 @@
 		if (err)
 			break;
 	} while (pgd++, addr = next, addr != end);
-	flush_cache_vmap(addr, end);
+	flush_cache_vmap(start, end);
 
 	if (unlikely(err))
 		return err;

Well yeah. This is what happens when functions modify their incoming arguments. It's a bad programming practice which leads directly to exactly this sort of bug.

How about we fix that?

mm/vmalloc.c renamed from mm/vmalloc.c~vmallocc-fix-flushing-in-vmap_page_range +1 -1
@@ -151,11 +151,12 @@ static int vmap_pud_range(pgd_t *pgd, un
  *
  * Ie. pte at addr+N*PAGE_SIZE shall point to pfn corresponding to pages[N]
  */
-static int vmap_page_range(unsigned long addr, unsigned long end,
+static int vmap_page_range(unsigned long start_addr, unsigned long end,
 				pgprot_t prot, struct page **pages)
 {
Quoted 8 lines

mm/vmalloc.c static int vmap_pud_range(pgd_t *pgd, un · line 159

Quoted 3 lines
mm/vmalloc.c renamed from mm/vmalloc.c~vmallocc-fix-flushing-in-vmap_page_range +1 -0
 	pgd_t *pgd;
 	unsigned long next;
+	unsigned long addr = start_addr;

Ugh, start_addr is an awful name. How about start? I know it doesn't hold the same amount of information but it's a local API, the pgd_offset_k() should make the unit unambiguous, it goes better with the end parameter and it's unique enough for this short function.

i'd like to observe that there's 449 start_addr instances in the kernel source, 17 of them in mm/*.c alone. So if it's 'ugly' (it isnt to me), this patch is not the place to start worrying about it. If you feel strongly about it then prepare a cleanup patch that eradicates them all, put your justification for why it's bad into the changelog and post it to lkml.

Anyway, happy bikeshed painting,

Ingo

#4 lore raw
Quoted 19 lines · Ingo Molnar
Quoted 10 lines
Quoted 10 lines
mm/vmalloc.c renamed from mm/vmalloc.c~vmallocc-fix-flushing-in-vmap_page_range +1 -1
@@ -151,11 +151,12 @@ static int vmap_pud_range(pgd_t *pgd, un
  *
  * Ie. pte at addr+N*PAGE_SIZE shall point to pfn corresponding to pages[N]
  */
-static int vmap_page_range(unsigned long addr, unsigned long end,
+static int vmap_page_range(unsigned long start_addr, unsigned long end,
 				pgprot_t prot, struct page **pages)
 {
Quoted 8 lines

mm/vmalloc.c static int vmap_pud_range(pgd_t *pgd, un · line 159

Quoted 3 lines
mm/vmalloc.c renamed from mm/vmalloc.c~vmallocc-fix-flushing-in-vmap_page_range +1 -0
 	pgd_t *pgd;
 	unsigned long next;
+	unsigned long addr = start_addr;

Ugh, start_addr is an awful name. How about start? I know it doesn't hold the same amount of information but it's a local API, the pgd_offset_k() should make the unit unambiguous, it goes better with the end parameter and it's unique enough for this short function.

Quoted 6 lines

i'd like to observe that there's 449 start_addr instances in the kernel source, 17 of them in mm/*.c alone. So if it's 'ugly' (it isnt to me), this patch is not the place to start worrying about it. If you feel strongly about it then prepare a cleanup patch that eradicates them all, put your justification for why it's bad into the changelog and post it to lkml.

It would surely not justify such a big change.

And at least in mm/* you have them paired with `end_addr' if they denote range start and end.

Hannes

#5 lore raw
In reply to Andrew Morton
Quoted 10 lines · Andrew Morton
Quoted 5 lines · On Thu, 25 Dec 2008 22:02:35 +0100 Adam Lackorzynski…

Hi,

in 2.6.28, the flush_cache_vmap in vmap_page_range() is called with the end of the range twice. The following patch fixes this for me.

Did this bug have any observeable runtime effects? If so, what were they?

Just in my own code, i.e. it doesn't have any effects to the kernel itself.

Quoted 5 lines

Well yeah. This is what happens when functions modify their incoming arguments. It's a bad programming practice which leads directly to exactly this sort of bug.

How about we fix that?

fine.

Quoted 17 lines
mm/vmalloc.c renamed from mm/vmalloc.c~vmallocc-fix-flushing-in-vmap_page_range +2 -1
@@ -151,11 +151,12 @@ static int vmap_pud_range(pgd_t *pgd, un
  *
  * Ie. pte at addr+N*PAGE_SIZE shall point to pfn corresponding to pages[N]
  */
-static int vmap_page_range(unsigned long addr, unsigned long end,
+static int vmap_page_range(unsigned long start_addr, unsigned long end,
 				pgprot_t prot, struct page **pages)
 {
 	pgd_t *pgd;
 	unsigned long next;
+	unsigned long addr = start_addr;
 	int err = 0;
 	int nr = 0;
 

mm/vmalloc.c static int vmap_page_range(unsigned long · line 174

Quoted 8 lines
mm/vmalloc.c renamed from mm/vmalloc.c~vmallocc-fix-flushing-in-vmap_page_range +1 -1
@@ -167,7 +168,7 @@ static int vmap_page_range(unsigned long
 		if (err)
 			break;
 	} while (pgd++, addr = next, addr != end);
-	flush_cache_vmap(addr, end);
+	flush_cache_vmap(start_addr, end);
 
 	if (unlikely(err))
 		return err;

Adam

Signature · 2 lines
Adam                 [email protected]
  Lackorzynski         http://os.inf.tu-dresden.de/~adam/