public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Mark Rutland <mark.rutland@arm.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [Resend RFC PATCH 1/2] armv8: Fix dcache disable function
Date: Mon, 24 Oct 2016 11:44:04 +0100	[thread overview]
Message-ID: <20161024104404.GD15620@leverpostej> (raw)
In-Reply-To: <c44917d7-4c71-b81f-a230-4f1565872f5b@wwwdotorg.org>

Hi,

Sorry for joining this a bit late; apologies if the below re-treads
ground already covered.

On Wed, Oct 19, 2016 at 09:25:02AM -0600, Stephen Warren wrote:
> On 10/14/2016 02:17 PM, York Sun wrote:
> >Current code turns off d-cache first, then flush all levels of cache.
> >This results data loss. As soon as d-cache is off, the dirty cache
> >is discarded according to the test on LS2080A. This issue was not
> >seen as long as external L3 cache was flushed to push the data to
> >main memory. However, external L3 cache is not guaranteed to have
> >the data. To fix this, flush the d-cache by way/set first to make
> >sure cache is clean before turning it off.
> 
> >diff --git a/arch/arm/cpu/armv8/cache_v8.c b/arch/arm/cpu/armv8/cache_v8.c
> 
> >@@ -478,9 +478,9 @@ void dcache_disable(void)
> 
> >+	flush_dcache_all();
> > 	set_sctlr(sctlr & ~(CR_C|CR_M));
> >
> >-	flush_dcache_all();
> > 	__asm_invalidate_tlb_all();
> 
> I talked to Mark Rutland at ARM, and I believe the current code is
> correct.

Well, almost, but not quite. It's a long story... ;)

I gave a primer [1,2] on the details at ELC earlier this year, which may
or may not be useful.

The big details are:

* Generaly "Flush" is ambiguous/meaningless. Here you seem to want
  clean+invalidate.

* Set/Way operations are for IMPLEMENTATION DEFINED (i.e. SoC-specific)
  cache maintenance sequences, and are not truly portable (e.g. not
  affecting system caches).
  
  I assume that an earlier boot stage initialised the caches prior to
  U-Boot. Given that, you *only* need to perform maintenance for the
  memory you have (at any point) mapped with cacheable attrbiutes, which
  should be a small subset of the PA space. With ARMv8-A, broadcast
  maintenance to the PoC should affect all relevant caches (assuming you
  use the correct shareability attributes).

* You *cannot* write a dcache disable routine in C, as the compiler can
  perform a number of implicit memory accesses (e.g. stack, globals,
  GOT). For that alone, I do not believe the code above is correct.

  Note that we have seen this being an issue in practice, before we got
  rid of Set/Way ops from arm64 Linux (see commit 5e051531447259e5).

* Your dcache disable code *must* be clean to the PoC, prior to
  execution, or instruction fetches could see stale data. You can first
  *clean* this to the PoC, which is sufficient to avoid the problems
  above.

* The SCTLR_ELx.{C,I} bits do not enable/disable caches; they merely
  activate/deactiveate cacheable attributes on data/instruction fetches.

  Note that cacheable instruction fetches can allocate into unified/data
  caches.
  
  Also, note that the I bit is independent of the C bit, and the
  attributes it provides differ when the M bit is clear. Generally, I
  would advise that at all times M == C == I, as that leads to the least
  surprise.

Thanks,
Mark.

[1] http://events.linuxfoundation.org/sites/events/files/slides/slides_17.pdf
[2] https://www.youtube.com/watch?v=F0SlIMHRnLk

  parent reply	other threads:[~2016-10-24 10:44 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-14 20:17 [U-Boot] [Resend RFC PATCH 0/2] Fix armv8 cache flushing York Sun
2016-10-14 20:17 ` [U-Boot] [Resend RFC PATCH 1/2] armv8: Fix dcache disable function York Sun
2016-10-14 20:23   ` Stephen Warren
2016-10-17 21:22   ` Stephen Warren
2016-10-19 15:25   ` Stephen Warren
2016-10-19 17:18     ` Stephen Warren
2016-10-19 22:32       ` york sun
2016-10-19 23:01         ` Stephen Warren
2016-10-20  5:06           ` york sun
2016-10-20 18:34             ` Stephen Warren
2016-10-21 19:31               ` york sun
2016-10-24 10:59                 ` Mark Rutland
2016-10-26 19:47                   ` Stephen Warren
2016-10-26 19:54                     ` york sun
2016-10-26 20:12                       ` Stephen Warren
2016-10-26 20:29                         ` york sun
2016-10-26 21:00                           ` Stephen Warren
2016-10-26 21:04                             ` york sun
     [not found]                     ` <d51c8f86-19c7-48d8-9335-097e8f574b76@nxp.com>
2016-10-26 21:02                       ` york sun
     [not found]                       ` <060025e2-128b-8c11-1804-fab1aa686f85@nxp.com>
2016-10-28 17:38                         ` york sun
2016-10-28 17:56                           ` Stephen Warren
2016-10-28 18:17                             ` york sun
2016-10-28 18:32                               ` Stephen Warren
2016-10-28 21:35                                 ` york sun
2016-11-07 14:11                                   ` Mark Rutland
2016-11-07 16:23                                     ` york sun
2016-11-07 14:03                                 ` Mark Rutland
2016-10-24 10:44     ` Mark Rutland [this message]
2016-10-26 19:41       ` Stephen Warren
2016-10-14 20:17 ` [U-Boot] [Resend RFC PATCH 2/2] armv8: Fix flush_dcache_all function York Sun
2016-10-14 20:29   ` Stephen Warren
2016-10-14 20:38     ` york sun

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=20161024104404.GD15620@leverpostej \
    --to=mark.rutland@arm.com \
    --cc=u-boot@lists.denx.de \
    /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