From: linux@arm.linux.org.uk (Russell King - ARM Linux)
To: linux-arm-kernel@lists.infradead.org
Subject: Unnecessary cache-line flush on page table updates ?
Date: Mon, 4 Jul 2011 14:05:21 +0100 [thread overview]
Message-ID: <20110704130521.GF8286@n2100.arm.linux.org.uk> (raw)
In-Reply-To: <20110704104329.GD19117@e102109-lin.cambridge.arm.com>
On Mon, Jul 04, 2011 at 11:43:29AM +0100, Catalin Marinas wrote:
> On Mon, Jul 04, 2011 at 11:02:21AM +0100, Russell King - ARM Linux wrote:
> > The single-TLB model works fairly well, but as I thought the lack of
> > mcr%? processing by GCC makes the asm/tlbflush.h code fairly disgusting
> > even for a v6+v7 kernel. Luckily, we can play some tricks and sort
> > some of that out. The patch below is not complete (and can result in
> > some rules of the architecture being violated - namely the requirement
> > for an ISB after the BTB flush without a branch between) but it
> > illustrates the idea:
>
> I'm not sure about this rule, I can ask for some clarification (we are
> not changing the memory map of the branch we execute).
There's no need for clarification on the BTB and branch issue, the
ARM ARM is quite clear on this topic:
Branch predictor maintenance operations and the memory order model
The following rule describes the effect of the memory order model on
the branch predictor maintenance operations:
? Any invalidation of the branch predictor is guaranteed to take effect only
after one of the following:
? execution of a ISB instruction
? taking an exception
? return from an exception.
Therefore, if a branch instruction appears between an invalidate branch
prediction instruction and an ISB operation, exception entry or exception
return, it is UNPREDICTABLE whether the branch instruction is affected by
the invalidate. Software must avoid this ordering of instructions, because
it might lead to UNPREDICTABLE behavior.
The branch predictor maintenance operations must be used to invalidate
entries in the branch predictor after any of the following events:
? enabling or disabling the MMU
? writing new data to instruction locations
? writing new mappings to the translation tables
? changes to the TTBR0, TTBR1, or TTBCR registers, unless accompanied by
a change to the ContextID or the FCSE ProcessID.
Failure to invalidate entries might give UNPREDICTABLE results, caused by
the execution of old branches.
So:
mcr p15, 0, %0, c7, c5, 6 @ BTC invalidate
tst %1, #value
beq no_dsb_isb
dsb
isb
no_dsb_isb:
is strictly not predictable whether the branch will be taken.
The only remaining question is: the operations prior to the BTC invalidate
will not have changed the code path which 'beq' is a part of, so is it
_really_ the case that a BTC invalidate will make such a branch
unpredictable?
I guess the reason for this is that if the BTC is half-way through an
invalidate, its state may not be determinable, and so it is not
determinable whether the branch will be taken irrespective of the
previous BTC state before the invalidate and the new state after the
isb.
Or, to put it another way, the BTC can return random results between
the BTC invalidate and the following ISB.
next prev parent reply other threads:[~2011-07-04 13:05 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-07-01 7:04 Unnecessary cache-line flush on page table updates ? heechul Yun
2011-07-01 10:10 ` Catalin Marinas
2011-07-01 21:42 ` heechul Yun
2011-07-04 9:45 ` Catalin Marinas
2011-07-04 10:02 ` Russell King - ARM Linux
2011-07-04 10:43 ` Catalin Marinas
2011-07-04 11:13 ` Russell King - ARM Linux
2011-07-04 15:58 ` Catalin Marinas
2011-07-04 19:58 ` Russell King - ARM Linux
2011-07-04 23:20 ` Russell King - ARM Linux
2011-07-06 16:05 ` Catalin Marinas
2011-07-06 18:08 ` Russell King - ARM Linux
2011-07-11 16:49 ` Catalin Marinas
2011-07-11 17:01 ` Russell King - ARM Linux
2011-07-12 13:09 ` Catalin Marinas
2011-07-15 16:24 ` Russell King - ARM Linux
2011-07-05 10:07 ` Catalin Marinas
2011-07-04 21:55 ` Russell King - ARM Linux
2011-07-05 9:26 ` Catalin Marinas
2011-07-05 9:46 ` Russell King - ARM Linux
2011-07-06 15:52 ` Catalin Marinas
2011-07-06 15:55 ` Russell King - ARM Linux
2011-07-06 16:15 ` Catalin Marinas
2011-07-05 10:48 ` Russell King - ARM Linux
2011-07-05 13:54 ` Catalin Marinas
2011-07-05 14:15 ` Russell King - ARM Linux
2011-07-05 14:40 ` Catalin Marinas
2011-07-04 13:05 ` Russell King - ARM Linux [this message]
2011-07-04 13:15 ` Catalin Marinas
2011-07-04 14:59 ` heechul Yun
2011-07-04 21:24 ` heechul Yun
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=20110704130521.GF8286@n2100.arm.linux.org.uk \
--to=linux@arm.linux.org.uk \
--cc=linux-arm-kernel@lists.infradead.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;
as well as URLs for NNTP newsgroup(s).