public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Leonid Yegoshin <Leonid.Yegoshin@imgtec.com>
To: Ralf Baechle <ralf@linux-mips.org>
Cc: <linux-mips@linux-mips.org>, <david.daney@cavium.com>,
	<cernekee@gmail.com>, <linux-kernel@vger.kernel.org>,
	<macro@codesourcery.com>, <markos.chandras@imgtec.com>,
	<kumba@gentoo.org>
Subject: Re: [PATCH] MIPS: bugfix of local_r4k_flush_icache_range - added L2 flush
Date: Wed, 10 Jun 2015 13:00:09 -0700	[thread overview]
Message-ID: <55789749.3070700@imgtec.com> (raw)
In-Reply-To: <20150610102805.GF2753@linux-mips.org>

On 06/10/2015 03:28 AM, Ralf Baechle wrote:
> On Thu, May 28, 2015 at 01:37:24PM -0700, Leonid Yegoshin wrote:
>
>> ...
> I was wondering why there was a cache flush at all so I dove into git
> history and found:
>
> commit 4676f9359fa5190ee6f42bbf2c27d28beb14d26a
> Author: Leonid Yegoshin <Leonid.Yegoshin@imgtec.com>
> Date:   Tue Jan 21 09:48:48 2014 +0000
>
>      MIPS: mm: c-r4k: Flush scache to avoid cache aliases
>      
>      There is a chance for the secondary cache to have memory
>      aliases. This can happen if the bootloader is in a non-EVA mode
>      (or even in EVA mode but with different mapping from the kernel)
>      and the kernel switching to EVA afterwards. It's best to flush
>      the icache to avoid having the secondary CPUs fetching stale
>      data from it.
>      
>      Signed-off-by: Leonid Yegoshin <Leonid.Yegoshin@imgtec.com>
>      Signed-off-by: Markos Chandras <markos.chandras@imgtec.com>
>
> flush_icache_range() really only is meant to deal with I-cache coherency
> issues as they appear during normal kernel operation, that is code is
> modified and will be executed from RAM.  I doesn't know about aliases
> and it's not meant to know.

1) OK, here is an explanation of memory aliasing (don't mix with cache 
aliasing).

Memory blocks bigger than 512MB should be put somewhere above 512MB 
physical address due to IO hole but we still need some memory at 
physical address 0x0000000. Board designers often prefer using masking 
of some address bits to MIRROR 256-512MB into 0x00000000 from a primary 
memory space location (for Malta - physical address 0x80000000). It 
decreases latency by some bus clocks (which are not CPU clocks but slowly).

So, in Malta the word at physical address 0x00000000-256MB is the same 
as word at physical address 0x80000000-0x90000000 (other boards may have 
another location). But cache subsystem knows NOTHING about it and caches 
that memory twice. This is a memory aliasing and it may cause a lot of 
trouble if system uses both aliasing address ranges. But it is pretty 
often that system initially uses low block 0x00000000->512MB during core 
startup and later switches to primary address space. So, some full L1D 
and L2 cache flush is needed after cache is initialized. However, after 
creation of exception handler code it is still needed additionally a 
flush of that code too, in L1D/I and including L2 in EVA, to avoid 
memory aliasing problem.

2) This patch actually notices that EJTAG and NMI exception handlers 
work with Status.ERL bit and pull exception handler code from uncachable 
memory, so a flushing exception handlers down to memory (including L2) 
is needed for that because of different reason. Actually, it is a result 
of debugging NMI with U-Boot. It is just by chance that it uses the same 
code and solution as EVA flushing.

>
> As I understand you only need this on startup.  Making this function work
> for your special use results in a performance penalty for every other user
> of this function.

Function local_r4k_flush_icache_range() can be used only at startup, 
before SMP is inialized. Original code has comment above this function:

/* This function is used only for local CPU only while boot etc */

I don't know why it disappeared.

>
> How about reverting this commit and calling __flush_cache_all() to
> make sure your kernel code gets flushed out to the other end of the
> universe - or memory, what ever comes first?

That function may call SMP IPI in some vendor CPUs and is not suitable.

But I agree that name local_r4k_flush_icache_range() is a not good now 
and it may be changed to something more appropriate. I am just not good 
in name changing game.

- Leonid.

>
>    Ralf


      reply	other threads:[~2015-06-10 20:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-28 20:37 [PATCH] MIPS: bugfix of local_r4k_flush_icache_range - added L2 flush Leonid Yegoshin
2015-06-10 10:28 ` Ralf Baechle
2015-06-10 20:00   ` Leonid Yegoshin [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55789749.3070700@imgtec.com \
    --to=leonid.yegoshin@imgtec.com \
    --cc=cernekee@gmail.com \
    --cc=david.daney@cavium.com \
    --cc=kumba@gentoo.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@linux-mips.org \
    --cc=macro@codesourcery.com \
    --cc=markos.chandras@imgtec.com \
    --cc=ralf@linux-mips.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox