Skip to contentSkip to conversation

missing data cache flush in trap_init?

PATCH Jun Sun 3 participants 5 messages Jan 3, 2001 – Jan 4, 2001 MIPS

lore
Share & tools
lore

Jun Sun

author
#0 lore raw

Ralf,

Someone reported this bug to me. I think it is a valid one. Basically trap_init() installs the vectors through kseg0 address and then flushes icache. It is possible that the vectors are still in the data cache and not written back to memory yet. If an exception happens it may get the corrupted the vector value.

The following patch should fix it. I am not sure if I can use flush_cache_range() to have potentially better performance.

Jun

arch/mips/kernel/traps.c Tue Jan 2 16:50:59 2001 renamed from arch/mips/kernel/traps.c.orig Tue Jan 2 16:24:16 2001 +1 -1
@@ -767,7 +767,7 @@
        default:
                panic("Unknown CPU type");
        }
-       flush_icache_range(KSEG0, KSEG0 + 0x200);
+       flush_cache_all();
 
        atomic_inc(&init_mm.mm_count);  /* XXX  UP?  */
        current->active_mm = &init_mm;
#1 lore raw
Quoted 2 lines · Jun Sun

The following patch should fix it. I am not sure if I can use flush_cache_range() to have potentially better performance.

Yes, flush_cache_range() is the right function and it should be used even
if no performance gain is achieved (it is in this case, though). I can't comment if that's needed at all, though. R3k which I use has its data cache write-through so it doesn't need such a change. I might check IDT R4k and possibly IDT R5k docs yet but I have no idea about other implementations.

Signature · 3 lines
+  Maciej W. Rozycki, Technical University of Gdansk, Poland   +
+--------------------------------------------------------------+
+        e-mail: [email protected], PGP key available        +
#2 lore raw
In reply to Jun Sun
Quoted 8 lines · Jun Sun

Someone reported this bug to me. I think it is a valid one. Basically trap_init() installs the vectors through kseg0 address and then flushes icache. It is possible that the vectors are still in the data cache and not written back to memory yet. If an exception happens it may get the corrupted the vector value.

The following patch should fix it. I am not sure if I can use flush_cache_range() to have potentially better performance.

Flush_icache_range is correct; the function is expected to do any dcache writebacks etc. to make dcache / icache / memory coherent.

Is it possible that you're using a CPU with additional vectors that aren't flushed by this flush_icache_call or?

Ralf

author
#3 lore raw
Quoted 12 lines · Ralf Baechle
Quoted 8 lines · Jun Sun

Someone reported this bug to me. I think it is a valid one. Basically trap_init() installs the vectors through kseg0 address and then flushes icache. It is possible that the vectors are still in the data cache and not written back to memory yet. If an exception happens it may get the corrupted the vector value.

The following patch should fix it. I am not sure if I can use flush_cache_range() to have potentially better performance.

Quoted 7 lines

Flush_icache_range is correct; the function is expected to do any dcache writebacks etc. to make dcache / icache / memory coherent.

Is it possible that you're using a CPU with additional vectors that aren't flushed by this flush_icache_call or?

Ralf

You are right - flush_icache_range() practically flushes both caches in the current implementation. There might be some other problems.

Aside of that, the name of flush_icache_range() seems to be misleading. Also in general how does it know which part of dcache to flush() without a given process mm struct? If it does not know, the only choice is to flush the whole dcache, which seems to make this function very close to flush_all().

Is this function introduced by other CPU platforms? How would it make a difference there? I am just curious ...

Jun

#4 lore raw
Quoted 3 lines · Jun Sun

Aside of that, the name of flush_icache_range() seems to be misleading. Also in general how does it know which part of dcache to flush() without a given process mm struct?

The function is only intended to flush kernel addresses for which no mm exists. Yes, it's being abused in creative ways but that's the purpose it was designed for ...

Quoted 5 lines

If it does not know, the only choice is to flush the whole
dcache, which seems to make this function very close to flush_all().

Is this function introduced by other CPU platforms? How would it make a difference there? I am just curious ...

Others such as for example m68k need it as well.

Ralf