Subject: vmalloc bugs in 2.4.5???

From: "machael" <[email-masked]>
Date: Mon, 5 Nov 2001 15:34:44 +0800

hello:
    I use linux-2.4.5 and I think VMALLOC may have some bugs which i don't
know how to fixup.
    I try to replace some kernel functions with my own implementations.I
will explain it in the following:
    Let's say:
        void (*my_func)(void)=func1;
     where "my_func" is a function pointer defined in kernel, and "func1" is
 a function(void func1(void)) implemented in kernel.And "my_func" is an
 EXPORTED SYMBOL in mips_ksyms.c.

    Now I want to replace "func1" with my own "func2" in a module
 my_module.o:
     extern void (*my_func)(void);
     my_func = func2;
     where "func2" is a function (void fun2(void)) implemented in
 "my_module.o".

     If I do "insmod my_module.o", the kernel should run OK. In fact, it is
 often met an "unhandled kernel unaligned access" or "do_page_fault"
 exception and then panics.

     We know "func1" should be in KSEG0(unmapped , cached) ,So it's address
should be 0x8XXXXXXX.And "my_func" should also pointed to this same address
before inserting
 my_module.o.  "func2" should be in KSEG2(mapped, cached) since it is
 implemented in module, So it's address should be 0xCXXXXXXX.After inserting
 my_module.o, "my_func" should be changed to pointed to this new address in
 KSEG2. But kernel panics......
    If I change "module_map()" in include/asm/module.h from vmalloc to
kmalloc, kernel runs ok after inserting my module. So I think vmalloc may
have some bugs.

    Anyone knows how to fixup it?

    machael

---

From: Ralf Baechle <[email-masked]>
Date: Tue, 6 Nov 2001 13:08:39 -0800

>     I use linux-2.4.5 and I think VMALLOC may have some bugs which i don't

Vmalloc is probably innocent I'd rather guess cache flushing is broken on
your platform.

  Ralf

---

From: "machael" <[email-masked]>
Date: Wed, 7 Nov 2001 08:47:18 +0800

> Vmalloc is probably innocent I'd rather guess cache flushing is broken on

Yes, It is possible. But I don't know how to fixup this broken cache
flushing?
And when and where should I flush cache (icache and dcache) manually?I am
really know little things about cache.

Can you help me?
Thank you very much.

machael

---

From: Atsushi Nemoto <[email-masked]>
Date: Wed, 07 Nov 2001 10:39:47 +0900 (JST)

>>>>> On Tue, 6 Nov 2001 13:08:39 -0800, Ralf Baechle <[email-masked]> said:
ralf> Vmalloc is probably innocent I'd rather guess cache flushing is
ralf> broken on your platform.

In 2.4.5, flush_cache_all() (and flush_tlb_all()) is called in
vmalloc_area_pages().  I think this call protect us from virtual
aliasing problem.

By the way, does anybody have any problem with vmalloc on recent
kernel?

In somewhere between 2.4.6 and 2.4.9, the call to flush_cache_all()
disappered from vmalloc_area_pages().  I have a data corruption
problem in vmalloc()ed area without this call.  I think we still need
this call.

--- linux-sgi-cvs/mm/vmalloc.c	Tue Sep 18 05:16:31 2001
+++ linux.new/mm/vmalloc.c	Wed Nov  7 10:33:47 2001
@@ -144,6 +144,7 @@
 	int ret;
 
 	dir = pgd_offset_k(address);
+	flush_cache_all();
 	spin_lock(&init_mm.page_table_lock);
 	do {
 		pmd_t *pmd;
@@ -163,6 +164,7 @@
 		ret = 0;
 	} while (address && (address < end));
 	spin_unlock(&init_mm.page_table_lock);
+ 	flush_tlb_all();
 	return ret;
 }
 
---
Atsushi Nemoto

---

From: "machael" <[email-masked]>
Date: Wed, 7 Nov 2001 10:09:49 +0800

> +++ linux.new/mm/vmalloc.c Wed Nov  7 10:33:47 2001

In 2.4.5, vmalloc has these two lines in vmalloc_area_pages().
So what else may be the problem?
Thanks!

machael

---

From: Ralf Baechle <[email-masked]>
Date: Wed, 7 Nov 2001 02:41:46 -0800

> problem in vmalloc()ed area without this call.  I think we still need

Entirely correct.  I'm just trying to find why this call got removed
in 2.4.10.  Clearly wrong;  I had not noticed that these two lines
got removed and thus was assuming the code of those two must somehow
be malfunctioning.

  Ralf

---

From: "machael" <[email-masked]>
Date: Wed, 7 Nov 2001 19:29:59 +0800

> got removed and thus was assuming the code of those two must somehow

I have added these two lines to vmalloc_area_pages in 2.4.10,but the
problems  still appear.
Why?

machael

---

From: "Maciej W. Rozycki" <[email-masked]>
Date: Thu, 8 Nov 2001 16:16:58 +0100 (MET)

> got removed and thus was assuming the code of those two must somehow

 See a mail titled "flush_tlb_all in vmalloc_area_pages" dated Sep 7th,
2001 sent to the linux-kernel list for the patch in question.  There was a
discussion on cache flushing wrt to a TLB on the list under "[PATCH]
change name of rep_nop" subject later as well.

-- 
+  Maciej W. Rozycki, Technical University of Gdansk, Poland   +
+--------------------------------------------------------------+
+        e-mail: [email-masked], PGP key available        +